From 3956ac7d094c3824bb18c9a2b49fd156533dd2ef Mon Sep 17 00:00:00 2001 From: Mikhail Burakov Date: Sun, 9 Apr 2023 14:17:16 +0200 Subject: Fix occasional issues appearing on client disconnection --- main.c | 12 ++++++------ toolbox | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/main.c b/main.c index 121085a..1b27a0d 100644 --- a/main.c +++ b/main.c @@ -108,10 +108,6 @@ static void MaybeDropClient(struct Contexts* contexts) { close(contexts->client_fd); contexts->client_fd = -1; } - if (timerfd_settime(contexts->timer_fd, 0, &spec, NULL)) { - LOG("Failed to disarm timer (%s)", strerror(errno)); - g_signal = SIGABRT; - } } static void OnTimerExpire(void* user) { @@ -130,8 +126,12 @@ static void OnTimerExpire(void* user) { return; } if (contexts->client_fd == -1) { - // TODO(mburakov): Is this actually possible? - LOG("Timer expired with disconnected client"); + // mburakov: Timer must disarm itself AFTER reading. + static const struct itimerspec spec = {0}; + if (timerfd_settime(contexts->timer_fd, 0, &spec, NULL)) { + LOG("Failed to disarm timer (%s)", strerror(errno)); + g_signal = SIGABRT; + } return; } diff --git a/toolbox b/toolbox index c5ca05d..c5334a4 160000 --- a/toolbox +++ b/toolbox @@ -1 +1 @@ -Subproject commit c5ca05dd86910984cb3ab7e3a17718f7be6ba274 +Subproject commit c5334a46523b9ac959c002fbc23a25eeccf63599 -- cgit v1.2.3