diff --git a/CHANGELOG.md b/CHANGELOG.md index a48cd33f8..e80b76a72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ **Features**: - Add option to attach screenshots on Windows to fatal error events. ([#1170](https://github.com/getsentry/sentry-native/pull/1170)) +- Add an option for `Crashpad` on Linux to delay application shutdown until the upload of the crash report in the `crashpad_handler` is complete. This is useful for deployment in `Docker` or `systemd`, where the life cycle of additional processes is bound by the application life cycle. ([#1153](https://github.com/getsentry/sentry-native/pull/1153), [crashpad#121](https://github.com/getsentry/crashpad/pull/121)) ## 0.8.2 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c9bf5ac8b..1d576b78f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -157,6 +157,10 @@ The example currently supports the following commands: - `capture-transaction`: Captures a transaction. - `traces-sampler`: Installs a traces sampler callback function when used alongside `capture-transaction`. + +Only on Linux using crashpad: +- `crashpad-wait-for-upload`: Couples application shutdown to complete the upload in the `crashpad_handler`. + Only on Windows using crashpad with its WER handler module: - `fastfail`: Crashes the application using the `__fastfail` intrinsic directly, thus by-passing SEH. diff --git a/examples/example.c b/examples/example.c index 6ac07fde6..c2c953a94 100644 --- a/examples/example.c +++ b/examples/example.c @@ -286,6 +286,10 @@ main(int argc, char **argv) sentry_options_set_proxy(options, "socks5://127.0.0.1:1080"); } + if (has_arg(argc, argv, "crashpad-wait-for-upload")) { + sentry_options_set_crashpad_wait_for_upload(options, true); + } + sentry_init(options); if (!has_arg(argc, argv, "no-setup")) { diff --git a/external/crashpad b/external/crashpad index 18c8a3528..2d97a484b 160000 --- a/external/crashpad +++ b/external/crashpad @@ -1 +1 @@ -Subproject commit 18c8a3528d9493855f7e6230ad84b7de51d220a9 +Subproject commit 2d97a484bb628b05a46203e4a05c6c827796e5cd diff --git a/include/sentry.h b/include/sentry.h index 30e03217f..c52d7336e 100644 --- a/include/sentry.h +++ b/include/sentry.h @@ -1288,8 +1288,17 @@ SENTRY_API void sentry_options_set_system_crash_reporter_enabled( sentry_options_t *opts, int enabled); /** - * Sets the maximum time (in milliseconds) to wait for the asynchronous tasks to - * end on shutdown, before attempting a forced termination. + * Enables a wait for the crash report upload to be finished before shutting + * down. This is disabled by default. + * + * This setting only has an effect when using the `crashpad` backend on Linux. + */ +SENTRY_API void sentry_options_set_crashpad_wait_for_upload( + sentry_options_t *opts, int wait_for_upload); + +/** + * Sets the maximum time (in milliseconds) to wait for the asynchronous + * tasks to end on shutdown, before attempting a forced termination. */ SENTRY_API void sentry_options_set_shutdown_timeout( sentry_options_t *opts, uint64_t shutdown_timeout); diff --git a/src/backends/sentry_backend_crashpad.cpp b/src/backends/sentry_backend_crashpad.cpp index 9012d4772..9ddca42fe 100644 --- a/src/backends/sentry_backend_crashpad.cpp +++ b/src/backends/sentry_backend_crashpad.cpp @@ -479,7 +479,8 @@ crashpad_backend_startup( bool success = data->client->StartHandler(handler, database, database, minidump_url ? minidump_url : "", proxy_url, annotations, arguments, /* restartable */ true, - /* asynchronous_start */ false, attachments, screenshot); + /* asynchronous_start */ false, attachments, screenshot, + options->crashpad_wait_for_upload); sentry_free(minidump_url); #ifdef SENTRY_PLATFORM_WINDOWS diff --git a/src/sentry_options.c b/src/sentry_options.c index 216ef2467..6a6b17429 100644 --- a/src/sentry_options.c +++ b/src/sentry_options.c @@ -48,6 +48,7 @@ sentry_options_new(void) opts->auto_session_tracking = true; opts->system_crash_reporter_enabled = false; opts->attach_screenshot = false; + opts->crashpad_wait_for_upload = false; opts->symbolize_stacktraces = // AIX doesn't have reliable debug IDs for server-side symbolication, // and the diversity of Android makes it infeasible to have access to debug @@ -452,6 +453,13 @@ sentry_options_set_system_crash_reporter_enabled( opts->system_crash_reporter_enabled = !!enabled; } +void +sentry_options_set_crashpad_wait_for_upload( + sentry_options_t *opts, int wait_for_upload) +{ + opts->crashpad_wait_for_upload = !!wait_for_upload; +} + void sentry_options_set_shutdown_timeout( sentry_options_t *opts, uint64_t shutdown_timeout) diff --git a/src/sentry_options.h b/src/sentry_options.h index 342c9db4c..6ca477b43 100644 --- a/src/sentry_options.h +++ b/src/sentry_options.h @@ -49,6 +49,7 @@ struct sentry_options_s { bool symbolize_stacktraces; bool system_crash_reporter_enabled; bool attach_screenshot; + bool crashpad_wait_for_upload; sentry_attachment_t *attachments; sentry_run_t *run; diff --git a/tests/test_integration_crashpad.py b/tests/test_integration_crashpad.py index f835d6578..614cfd6ee 100644 --- a/tests/test_integration_crashpad.py +++ b/tests/test_integration_crashpad.py @@ -522,7 +522,8 @@ def test_disable_backend(cmake, httpserver): @pytest.mark.skipif( - sys.platform != "darwin", reason="retry mechanism test only runs on macOS" + sys.platform != "darwin" or not os.getenv("CI"), + reason="retry mechanism test only runs on macOS in CI", ) def test_crashpad_retry(cmake, httpserver): tmp_path = cmake(["sentry_example"], {"SENTRY_BACKEND": "crashpad"})