Skip to content

Comments

Add explicit SIGTERM and SIGINT handlers.#1106

Merged
eakraly merged 2 commits intocoturn:masterfrom
wireapp:wireapp/signal-handlers
Dec 7, 2022
Merged

Add explicit SIGTERM and SIGINT handlers.#1106
eakraly merged 2 commits intocoturn:masterfrom
wireapp:wireapp/signal-handlers

Conversation

@sysvinit
Copy link
Contributor

coturn running inside a docker container runs as PID 1, however PID 1 has special signal handling semantics (see the note at the bottom of the section here). coturn relies on the default behaviour of SIGTERM to terminate the process, however as no signal handler is explicitly installed, it doesn't respond to SIGTERM when running inside a container. This PR fixes this problem by installing explicit signal handlers for SIGINT and SIGTERM, which trigger the same termination mechanism as the admin interface "halt" command.

This is a port of wireapp#6 for upstream.

This is required in order for these signals to be received properly when coturn
is running as pid 1 inside a container, as signal handling for pid 1 (in any
pid namespace) is special.
@sysvinit sysvinit force-pushed the wireapp/signal-handlers branch from eea1d66 to d565690 Compare November 24, 2022 11:55
}

static void shutdown_handler(evutil_socket_t sock, short events, void *args) {
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "Caught signal, terminating\n");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot know what signal was sent
Should we have different handlers (per signal) instead?
Will look like code duplication but eventually will give us opportunity to handle different signals in different way (not to mention proper logging)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does cdec597 fix this issue? I took a quick look at the libevent documentation, and it seems that for signal handlers, the signal number is provided to the callback in the evutil_socket_t argument, so this value can be included in the log message.

@eakraly eakraly merged commit 82646a9 into coturn:master Dec 7, 2022
@sysvinit sysvinit deleted the wireapp/signal-handlers branch December 8, 2022 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants