[ObjC] fix lock inversion in dns service resolver shutdown (#38010)

In EventEngineClientChannelDNSResolver, it needs to acquire `on_resolved_mu_` lock when calling dns resolver APIs as well as in on_resolve callback.

In DNSServiceResolverImpl::LookupHostname, it acquires `request_mu_` lock, so the lock order is:
EventEngineClientChannelDNSResolver::on_resolved_mu_ -> DNSServiceResolverImpl::request_mu_

Upon the resolution successful or failed, DNSServiceResolverImpl calls the on_resolved callback without holding any locks, so only one lock here:
EventEngineClientChannelDNSResolver::on_resolved_mu_

However when DNSServiceResolver was deleted, in DNSServiceResolverImpl::Shutdown, it calls the on_resolve callbacks while holding the `request_mu_` lock, as a result the lock order becomes:
DNSServiceResolverImpl::request_mu_ -> EventEngineClientChannelDNSResolver::on_resolved_mu_
which triggers the deadlock check in absl::Mutex as these two locks are acquired in different orders.

This PR release the on_resolved_mu_ first before calling on_resolve, so abls won't complain.

Added a new test which fails with GPR_ABSEIL_SYNC=1 (not enabled by default) without this PR.

Closes #38010

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/38010 from HannahShiSFB:fix-lock-invert-in-dns-service-resolver-shutdown 5adc8f32b3ecbd96e7bd0a7c9850e6c0bb02c70d
PiperOrigin-RevId: 690781049
2 files changed
tree: e65a79d1698d4f8e050d14d20bb973aeca18029c
  1. .bazelci/
  2. .github/
  3. bazel/
  4. cmake/
  5. doc/
  6. etc/
  7. examples/
  8. fuzztest/
  9. include/
  10. spm-core-include/
  11. spm-cpp-include/
  12. src/
  13. summerofcode/
  14. templates/
  15. test/
  16. third_party/
  17. tools/
  18. .bazelignore
  19. .bazelrc
  20. .bazelversion
  21. .clang-format
  22. .clang-tidy
  23. .dockerignore
  24. .editorconfig
  25. .git-blame-ignore-revs
  26. .gitallowed
  27. .gitattributes
  28. .gitignore
  29. .gitmodules
  30. .istanbul.yml
  31. .pylintrc
  32. .pylintrc-examples
  33. .pylintrc-tests
  34. .rspec
  35. .yapfignore
  36. .yardopts
  37. _metadata.py
  38. AUTHORS
  39. black.toml
  40. BoringSSL-Package.swift
  41. BUILD
  42. build_autogenerated.yaml
  43. build_config.rb
  44. build_handwritten.yaml
  45. BUILDING.md
  46. CMakeLists.txt
  47. CODE-OF-CONDUCT.md
  48. composer.json
  49. CONCEPTS.md
  50. config.m4
  51. config.w32
  52. CONTRIBUTING.md
  53. CONTRIBUTING_STEPS.md
  54. Gemfile
  55. GOVERNANCE.md
  56. gRPC-C++.podspec
  57. gRPC-Core.podspec
  58. gRPC-ProtoRPC.podspec
  59. gRPC-RxLibrary.podspec
  60. grpc.bzl
  61. grpc.def
  62. grpc.gemspec
  63. gRPC.podspec
  64. LICENSE
  65. MAINTAINERS.md
  66. Makefile
  67. MANIFEST.md
  68. NOTICE.txt
  69. Package.swift
  70. package.xml
  71. PYTHON-MANIFEST.in
  72. Rakefile
  73. README.md
  74. requirements.bazel.txt
  75. requirements.txt
  76. SECURITY.md
  77. setup.cfg
  78. setup.py
  79. TROUBLESHOOTING.md
  80. WORKSPACE
README.md

gRPC – An RPC library and framework

gRPC is a modern, open source, high-performance remote procedure call (RPC) framework that can run anywhere. gRPC enables client and server applications to communicate transparently, and simplifies the building of connected systems.

Join the chat at https://gitter.im/grpc/grpc

To start using gRPC

To maximize usability, gRPC supports the standard method for adding dependencies to a user‘s chosen language (if there is one). In most languages, the gRPC runtime comes as a package available in a user’s language package manager.

For instructions on how to use the language-specific gRPC runtime for a project, please refer to these documents

  • C++: follow the instructions under the src/cpp directory
  • C#/.NET: NuGet packages Grpc.Net.Client, Grpc.AspNetCore.Server
  • Dart: pub package grpc
  • Go: go get google.golang.org/grpc
  • Java: Use JARs from Maven Central Repository
  • Kotlin: Use JARs from Maven Central Repository
  • Node: npm install @grpc/grpc-js
  • Objective-C: Add gRPC-ProtoRPC dependency to podspec
  • PHP: pecl install grpc
  • Python: pip install grpcio
  • Ruby: gem install grpc
  • WebJS: follow the grpc-web instructions

Per-language quickstart guides and tutorials can be found in the documentation section on the grpc.io website. Code examples are available in the examples directory.

Precompiled bleeding-edge package builds of gRPC master branch's HEAD are uploaded daily to packages.grpc.io.

To start developing gRPC

Contributions are welcome!

Please read How to contribute which will guide you through the entire workflow of how to build the source code, how to run the tests, and how to contribute changes to the gRPC codebase. The “How to contribute” document also contains info on how the contribution process works and contains best practices for creating contributions.

Troubleshooting

Sometimes things go wrong. Please check out the Troubleshooting guide if you are experiencing issues with gRPC.

Performance

See the Performance dashboard for performance numbers of master branch daily builds.

Concepts

See gRPC Concepts

About This Repository

This repository contains source code for gRPC libraries implemented in multiple languages written on top of a shared C++ core library src/core.

Libraries in different languages may be in various states of development. We are seeking contributions for all of these libraries:

LanguageSource
Shared C++ [core library]src/core
C++src/cpp
Rubysrc/ruby
Pythonsrc/python
PHPsrc/php
C# (core library based)src/csharp
Objective-Csrc/objective-c
LanguageSource repo
Javagrpc-java
Kotlingrpc-kotlin
Gogrpc-go
NodeJSgrpc-node
WebJSgrpc-web
Dartgrpc-dart
.NET (pure C# impl.)grpc-dotnet
Swiftgrpc-swift