Skip to content

Commit ce9d742

Browse files
feat(crashpad): add option to delay shutdown until crash report upload completes (Linux) (#1153)
* update crashpad * add sentry option `on_crash_wait_for_upload` * add CHANGELOG.md * typo * update crashpad + pass option * update crashpad * add `crashpad-wait-for-upload` to example * update crashpad + add empty test * update crashpad * update crashpad * skip retry test on local testing * Apply suggestions from code review Co-authored-by: Mischan Toosarani-Hausberger <[email protected]> * rename option to `crashpad_wait_for_upload` * update crashpad --------- Co-authored-by: Mischan Toosarani-Hausberger <[email protected]>
1 parent 884a714 commit ce9d742

File tree

9 files changed

+34
-5
lines changed

9 files changed

+34
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
**Features**:
66

77
- Add option to attach screenshots on Windows to fatal error events. ([#1170](https://github.com/getsentry/sentry-native/pull/1170))
8+
- 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))
89

910
## 0.8.2
1011

CONTRIBUTING.md

+4
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ The example currently supports the following commands:
157157
- `capture-transaction`: Captures a transaction.
158158
- `traces-sampler`: Installs a traces sampler callback function when used alongside `capture-transaction`.
159159

160+
161+
Only on Linux using crashpad:
162+
- `crashpad-wait-for-upload`: Couples application shutdown to complete the upload in the `crashpad_handler`.
163+
160164
Only on Windows using crashpad with its WER handler module:
161165

162166
- `fastfail`: Crashes the application using the `__fastfail` intrinsic directly, thus by-passing SEH.

examples/example.c

+4
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ main(int argc, char **argv)
286286
sentry_options_set_proxy(options, "socks5://127.0.0.1:1080");
287287
}
288288

289+
if (has_arg(argc, argv, "crashpad-wait-for-upload")) {
290+
sentry_options_set_crashpad_wait_for_upload(options, true);
291+
}
292+
289293
sentry_init(options);
290294

291295
if (!has_arg(argc, argv, "no-setup")) {

include/sentry.h

+11-2
Original file line numberDiff line numberDiff line change
@@ -1288,8 +1288,17 @@ SENTRY_API void sentry_options_set_system_crash_reporter_enabled(
12881288
sentry_options_t *opts, int enabled);
12891289

12901290
/**
1291-
* Sets the maximum time (in milliseconds) to wait for the asynchronous tasks to
1292-
* end on shutdown, before attempting a forced termination.
1291+
* Enables a wait for the crash report upload to be finished before shutting
1292+
* down. This is disabled by default.
1293+
*
1294+
* This setting only has an effect when using the `crashpad` backend on Linux.
1295+
*/
1296+
SENTRY_API void sentry_options_set_crashpad_wait_for_upload(
1297+
sentry_options_t *opts, int wait_for_upload);
1298+
1299+
/**
1300+
* Sets the maximum time (in milliseconds) to wait for the asynchronous
1301+
* tasks to end on shutdown, before attempting a forced termination.
12931302
*/
12941303
SENTRY_API void sentry_options_set_shutdown_timeout(
12951304
sentry_options_t *opts, uint64_t shutdown_timeout);

src/backends/sentry_backend_crashpad.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,8 @@ crashpad_backend_startup(
479479
bool success = data->client->StartHandler(handler, database, database,
480480
minidump_url ? minidump_url : "", proxy_url, annotations, arguments,
481481
/* restartable */ true,
482-
/* asynchronous_start */ false, attachments, screenshot);
482+
/* asynchronous_start */ false, attachments, screenshot,
483+
options->crashpad_wait_for_upload);
483484
sentry_free(minidump_url);
484485

485486
#ifdef SENTRY_PLATFORM_WINDOWS

src/sentry_options.c

+8
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ sentry_options_new(void)
4848
opts->auto_session_tracking = true;
4949
opts->system_crash_reporter_enabled = false;
5050
opts->attach_screenshot = false;
51+
opts->crashpad_wait_for_upload = false;
5152
opts->symbolize_stacktraces =
5253
// AIX doesn't have reliable debug IDs for server-side symbolication,
5354
// and the diversity of Android makes it infeasible to have access to debug
@@ -452,6 +453,13 @@ sentry_options_set_system_crash_reporter_enabled(
452453
opts->system_crash_reporter_enabled = !!enabled;
453454
}
454455

456+
void
457+
sentry_options_set_crashpad_wait_for_upload(
458+
sentry_options_t *opts, int wait_for_upload)
459+
{
460+
opts->crashpad_wait_for_upload = !!wait_for_upload;
461+
}
462+
455463
void
456464
sentry_options_set_shutdown_timeout(
457465
sentry_options_t *opts, uint64_t shutdown_timeout)

src/sentry_options.h

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ struct sentry_options_s {
4949
bool symbolize_stacktraces;
5050
bool system_crash_reporter_enabled;
5151
bool attach_screenshot;
52+
bool crashpad_wait_for_upload;
5253

5354
sentry_attachment_t *attachments;
5455
sentry_run_t *run;

tests/test_integration_crashpad.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,8 @@ def test_disable_backend(cmake, httpserver):
522522

523523

524524
@pytest.mark.skipif(
525-
sys.platform != "darwin", reason="retry mechanism test only runs on macOS"
525+
sys.platform != "darwin" or not os.getenv("CI"),
526+
reason="retry mechanism test only runs on macOS in CI",
526527
)
527528
def test_crashpad_retry(cmake, httpserver):
528529
tmp_path = cmake(["sentry_example"], {"SENTRY_BACKEND": "crashpad"})

0 commit comments

Comments
 (0)