From a9f38295bb215c55d66974b5dcbc6123f4709355 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Thu, 22 Jul 2021 18:23:37 +0200 Subject: [PATCH] daemon/session: fix an issue with timers The practical problem was also mitigated by libuv >= 1.32.0 (2ee2d46) --- daemon/session.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/daemon/session.c b/daemon/session.c index a0bf23f3f..668295ca0 100644 --- a/daemon/session.c +++ b/daemon/session.c @@ -503,18 +503,24 @@ int session_timer_start(struct session *session, uv_timer_cb cb, uint64_t timeout, uint64_t repeat) { uv_timer_t *timer = &session->timeout; + // Session might be closing and get here e.g. through a late on_send callback. + const bool is_closing = uv_is_closing((uv_handle_t *)timer); + if (is_closing || kr_fails_assert(is_closing == session->sflags.closing)) + return kr_error(EINVAL); + if (kr_fails_assert(timer->data == session)) return kr_error(EINVAL); int ret = uv_timer_start(timer, cb, timeout, repeat); if (ret != 0) { uv_timer_stop(timer); - return kr_error(ENOMEM); + return kr_error(ret); } - return 0; + return kr_ok(); } int session_timer_restart(struct session *session) { + kr_require(!uv_is_closing((uv_handle_t *)&session->timeout)); return uv_timer_again(&session->timeout); } -- 2.47.2