27-skip-child-post-fork-operations.patch 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. --- a/src/core/lib/event_engine/forkable.cc (index)
  2. +++ b/src/core/lib/event_engine/forkable.cc (working tree)
  3. @@ -62,8 +62,17 @@ void PostforkParent() {
  4. }
  5. }
  6. +bool skip_postfork_child = false;
  7. +
  8. +void SetSkipPostForkChild() {
  9. + skip_postfork_child = true;
  10. +}
  11. +
  12. void PostforkChild() {
  13. y_absl::ResetDeadlockGraphMu();
  14. + if (skip_postfork_child) {
  15. + return;
  16. + }
  17. grpc_core::MutexLock lock(g_mu.get());
  18. for (auto* forkable : *g_forkables) {
  19. forkable->PostforkChild();
  20. --- a/src/core/lib/event_engine/forkable.h (index)
  21. +++ b/src/core/lib/event_engine/forkable.h (working tree)
  22. @@ -28,6 +28,19 @@ namespace experimental {
  23. // This should be called once upon grpc_initialization.
  24. void RegisterForkHandlers();
  25. +// We've faced flickering crash in grpc during fork.
  26. +// Crash is observed in different places before 'execv' is called.
  27. +// It is mentioned in https://man7.org/linux/man-pages/man2/fork.2.html
  28. +// that in multithreading application not all function could be called
  29. +// after fork, so we think that we deal with 'undefined behaviour'.
  30. +// In original grpc code the threads are created during postfork operations,
  31. +// but thread creation is not safe in accordance to the fork documentation.
  32. +//
  33. +// So, if threads in child process are not required, user could
  34. +// skip threads recovery after fork for child process in order
  35. +// to exclude issues with possible UB.
  36. +void SetSkipPostForkChild();
  37. +
  38. // Global callback for pthread_atfork's *prepare argument
  39. void PrepareFork();
  40. // Global callback for pthread_atfork's *parent argument