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 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'main.c') 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; } -- cgit v1.2.3