From: Etienne Dechamps Date: Fri, 4 Jul 2014 23:23:05 +0000 (+0100) Subject: Fix tinc event loop reentrancy from timeout handlers. X-Git-Tag: release-1.1pre11~79 X-Git-Url: https://git.tinc-vpn.org/git/browse?a=commitdiff_plain;h=c786ed116805c0bc911f592c03dc0d5562287283;p=tinc 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 --- diff --git a/src/event.c b/src/event.c index f3497420..cb710a06 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;