Skip to content

Commit

Permalink
feat: Make shutdown timeout customizable (#577)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrei Muraru <andrei.muraru@avira.com>
  • Loading branch information
andrei-mu and Andrei Muraru committed Jul 15, 2021
1 parent c4bc734 commit 290fa46
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
13 changes: 13 additions & 0 deletions include/sentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 -- */

/**
Expand Down
3 changes: 1 addition & 2 deletions src/sentry_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
14 changes: 14 additions & 0 deletions src/sentry_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions src/sentry_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ typedef struct sentry_options_s {

long user_consent;
long refcount;
uint64_t shutdown_timeout;
} sentry_options_t;

/**
Expand Down

0 comments on commit 290fa46

Please sign in to comment.