From c786ed116805c0bc911f592c03dc0d5562287283 Mon Sep 17 00:00:00 2001 From: Etienne Dechamps Date: Sat, 5 Jul 2014 00:23:05 +0100 Subject: [PATCH] Fix tinc event loop reentrancy from timeout handlers. Commit 611217c96ec684799882cf330f40a0936131b6b5 introduced a regression because it accidentally reordered the timeout handler calls and the fdset setup code. This means that any io_add(), io_del() or io_set() calls in timeout handlers would be ignored in the current event loop iteration, resulting in erratic behavior. The most visible symptom is when a metaconnection timeout occurs and the connection is closed; the timeout handler closes the socket but it still ends up in the select() call, typically resulting in the following crash: Error while waiting for input: Bad file descriptor --- src/event.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/event.c b/src/event.c index f349742..cb710a0 100644 --- a/src/event.c +++ b/src/event.c @@ -256,10 +256,10 @@ bool event_loop(void) { fd_set writable; while(running) { - memcpy(&readable, &readfds, sizeof readable); - memcpy(&writable, &writefds, sizeof writable); struct timeval diff; struct timeval *tv = get_time_remaining(&diff); + memcpy(&readable, &readfds, sizeof readable); + memcpy(&writable, &writefds, sizeof writable); int fds = 0; -- 2.25.1