From 290fa46ec868b5f23f720fff253c1da8746ce249 Mon Sep 17 00:00:00 2001 From: andrei-mu Date: Thu, 15 Jul 2021 21:04:38 +0200 Subject: [PATCH] feat: Make shutdown timeout customizable (#577) Co-authored-by: Andrei Muraru --- include/sentry.h | 13 +++++++++++++ src/sentry_core.c | 3 +-- src/sentry_options.c | 14 ++++++++++++++ src/sentry_options.h | 1 + 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/include/sentry.h b/include/sentry.h index 8defce2be..bc9143739 100644 --- a/include/sentry.h +++ b/include/sentry.h @@ -1006,6 +1006,19 @@ SENTRY_API void sentry_options_set_database_pathw( 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. + */ +SENTRY_API void sentry_options_set_shutdown_timeout( + sentry_options_t *opts, uint64_t shutdown_timeout); + +/** + * Gets the maximum time (in milliseconds) to wait for the asynchronous tasks to + * end on shutdown, before attempting a forced termination. + */ +SENTRY_API uint64_t sentry_options_get_shutdown_timeout(sentry_options_t *opts); + /* -- Global APIs -- */ /** diff --git a/src/sentry_core.c b/src/sentry_core.c index 56f8e66b2..2904ce7c2 100644 --- a/src/sentry_core.c +++ b/src/sentry_core.c @@ -213,9 +213,8 @@ sentry_close(void) } if (options->transport) { - // TODO: make this configurable if (sentry__transport_shutdown( - options->transport, SENTRY_DEFAULT_SHUTDOWN_TIMEOUT) + options->transport, options->shutdown_timeout) != 0) { SENTRY_WARN("transport did not shut down cleanly"); } diff --git a/src/sentry_options.c b/src/sentry_options.c index 8468c2c58..82445ad61 100644 --- a/src/sentry_options.c +++ b/src/sentry_options.c @@ -47,6 +47,7 @@ sentry_options_new(void) opts->transport = sentry__transport_new_default(); opts->sample_rate = 1.0; opts->refcount = 1; + opts->shutdown_timeout = SENTRY_DEFAULT_SHUTDOWN_TIMEOUT; return opts; } @@ -297,6 +298,19 @@ sentry_options_set_system_crash_reporter_enabled( opts->system_crash_reporter_enabled = !!enabled; } +void +sentry_options_set_shutdown_timeout( + sentry_options_t *opts, uint64_t shutdown_timeout) +{ + opts->shutdown_timeout = shutdown_timeout; +} + +uint64_t +sentry_options_get_shutdown_timeout(sentry_options_t *opts) +{ + return opts->shutdown_timeout; +} + static void add_attachment(sentry_options_t *opts, sentry_path_t *path) { diff --git a/src/sentry_options.h b/src/sentry_options.h index 149a7fb06..c9eab8120 100644 --- a/src/sentry_options.h +++ b/src/sentry_options.h @@ -62,6 +62,7 @@ typedef struct sentry_options_s { long user_consent; long refcount; + uint64_t shutdown_timeout; } sentry_options_t; /**