heapprofd: Fix crash when tracing service disconnects

When the tracing service (traced) disconnects (because it crashes or
other reasons), if heapprofd has an active client, it will crash,
because:

* HeapprofdProducer::Restart() is executed.
* HeapprofdProducer destructor destroys its unwinding_workers_
* UnwindingWorker destroys its members. In order:
  * thread_task_runner_ is destroyed, so that the thread is stopped.
  * (If there's one connected client) client_data_ is destroyed.
  * ClientData includes a UnixSocket, which calls PostTask on
    thread_task_runner_.
  * thread_task_runner_ was destroyed earlier.

This patch makes fixes the problem by destroying client_data_ (on
thread_task_runner_) before destroying the thread_task_runner_ itself.

(this is a cherry-pick of just the test part of ag/20347035 since the
actual fix landed through a merge from tm-dev)

Bug: 233338564
Bug: 155759761
Change-Id: Id1874abbff8f7a7b702542a943a8de3f3a52277a
Merged-In: Id1874abbff8f7a7b702542a943a8de3f3a52277a
5 files changed
tree: 71384e2f54d7f3e53cbb6bb4736c60cbbf923675
  1. .github/
  2. bazel/
  3. build_overrides/
  4. buildtools/
  5. debian/
  6. docs/
  7. examples/
  8. gn/
  9. include/
  10. infra/
  11. protos/
  12. python/
  13. src/
  14. test/
  15. tools/
  16. ui/
  17. .clang-format
  18. .clang-tidy
  19. .git-blame-ignore-revs
  20. .gitattributes
  21. .gitignore
  22. .gn
  23. .style.yapf
  24. Android.bp
  25. Android.bp.extras
  26. BUILD
  27. BUILD.extras
  28. BUILD.gn
  29. CHANGELOG
  30. codereview.settings
  31. DIR_METADATA
  32. heapprofd.rc
  33. LICENSE
  34. meson.build
  35. METADATA
  36. MODULE_LICENSE_APACHE2
  37. OWNERS
  38. perfetto.rc
  39. PerfettoIntegrationTests.xml
  40. PRESUBMIT.py
  41. README.chromium
  42. README.md
  43. TEST_MAPPING
  44. traced_perf.rc
  45. WORKSPACE
README.md

Perfetto - System profiling, app tracing and trace analysis

Perfetto is a production-grade open-source stack for performance instrumentation and trace analysis. It offers services and libraries and for recording system-level and app-level traces, native + java heap profiling, a library for analyzing traces using SQL and a web-based UI to visualize and explore multi-GB traces.

See https://perfetto.dev/docs or the /docs/ directory for documentation.