Skip to content

Commit ac502af

Browse files
committed
lib: Avoid wrongly thinking time moved forwards for larger ioloop wait times
1 parent ca94055 commit ac502af

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/lib/ioloop.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
Dovecot generally doesn't have very important short timeouts, so to avoid
1919
logging many warnings about this, use a rather high value. */
2020
#define IOLOOP_TIME_MOVED_FORWARDS_MIN_USECS (100000)
21+
/* When the ioloop wait time is large, the "time moved forwards" detection
22+
can't be done as reliably. Apparently if we ask the kernel to wait for
23+
10000ms, it might think it's okay to stop after 10100ms or more. So use
24+
a larger value for larger timeouts. */
25+
#define IOLOOP_TIME_MOVED_FORWARDS_MIN_USECS_LARGE (1000000)
2126

2227
time_t ioloop_time = 0;
2328
struct timeval ioloop_timeval;
@@ -654,9 +659,13 @@ static void io_loop_handle_timeouts_real(struct ioloop *ioloop)
654659
/* the callback may have slept, so check the time again. */
655660
i_gettimeofday(&ioloop_timeval);
656661
} else {
662+
int max_diff = diff_usecs < IOLOOP_TIME_MOVED_FORWARDS_MIN_USECS_LARGE ?
663+
IOLOOP_TIME_MOVED_FORWARDS_MIN_USECS :
664+
IOLOOP_TIME_MOVED_FORWARDS_MIN_USECS_LARGE;
665+
657666
diff_usecs = timeval_diff_usecs(&ioloop->next_max_time,
658667
&ioloop_timeval);
659-
if (unlikely(-diff_usecs >= IOLOOP_TIME_MOVED_FORWARDS_MIN_USECS)) {
668+
if (unlikely(-diff_usecs >= max_diff)) {
660669
io_loops_timeouts_update(-diff_usecs);
661670
/* time moved forward */
662671
ioloop->time_moved_callback(&ioloop->next_max_time,

0 commit comments

Comments
 (0)