aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2024-12-09 12:49:19 +0000
committerVsevolod Stakhov <vsevolod@rspamd.com>2024-12-09 12:49:19 +0000
commit2b2b2762cc48f6be7a26c185bd95e7c77cdc46fa (patch)
tree698339cccacd6ca84182975df8bd1231bb50595f /src
parenteecb96c9eb45f6b6a8d66b4c3462c2d1a2371985 (diff)
downloadrspamd-2b2b2762cc48f6be7a26c185bd95e7c77cdc46fa.tar.gz
rspamd-2b2b2762cc48f6be7a26c185bd95e7c77cdc46fa.zip
[Fix] Use cumulative timeout when dealing with TCP connectionsvstakhov-cumulative-tcp-timeout
Diffstat (limited to 'src')
-rw-r--r--src/libutil/libev_helper.c9
-rw-r--r--src/libutil/libev_helper.h5
-rw-r--r--src/lua/lua_tcp.c8
3 files changed, 17 insertions, 5 deletions
diff --git a/src/libutil/libev_helper.c b/src/libutil/libev_helper.c
index 203e1ed73..82fead9bb 100644
--- a/src/libutil/libev_helper.c
+++ b/src/libutil/libev_helper.c
@@ -69,16 +69,21 @@ void rspamd_ev_watcher_start(struct ev_loop *loop,
}
}
-void rspamd_ev_watcher_stop(struct ev_loop *loop,
- struct rspamd_io_ev *ev)
+ev_tstamp rspamd_ev_watcher_stop(struct ev_loop *loop,
+ struct rspamd_io_ev *ev)
{
+ ev_tstamp elapsed = 0;
+
if (ev_can_stop(&ev->io)) {
ev_io_stop(EV_A, &ev->io);
}
if (ev->timeout > 0) {
+ elapsed = ev->timeout - ev_timer_remaining(EV_A, &ev->tm);
ev_timer_stop(EV_A, &ev->tm);
}
+
+ return elapsed;
}
void rspamd_ev_watcher_reschedule(struct ev_loop *loop,
diff --git a/src/libutil/libev_helper.h b/src/libutil/libev_helper.h
index d68f17951..be9917891 100644
--- a/src/libutil/libev_helper.h
+++ b/src/libutil/libev_helper.h
@@ -65,9 +65,10 @@ void rspamd_ev_watcher_start(struct ev_loop *loop,
* Stops watcher and clean it up
* @param loop
* @param ev
+ * @return {ev_tstamp} elapsed time
*/
-void rspamd_ev_watcher_stop(struct ev_loop *loop,
- struct rspamd_io_ev *ev);
+ev_tstamp rspamd_ev_watcher_stop(struct ev_loop *loop,
+ struct rspamd_io_ev *ev);
/**
* Convenience function to reschedule watcher with different events
diff --git a/src/lua/lua_tcp.c b/src/lua/lua_tcp.c
index f498f9598..bea8d2ef9 100644
--- a/src/lua/lua_tcp.c
+++ b/src/lua/lua_tcp.c
@@ -1099,11 +1099,17 @@ lua_tcp_handler(int fd, short what, gpointer ud)
TCP_RETAIN(cbd);
msg_debug_tcp("processed TCP event: %d", what);
+ ev_tstamp elapsed;
struct lua_tcp_handler *rh = g_queue_peek_head(cbd->handlers);
event_type = rh->type;
- rspamd_ev_watcher_stop(cbd->event_loop, &cbd->ev);
+ elapsed = rspamd_ev_watcher_stop(cbd->event_loop, &cbd->ev);
+
+ /* Adjust timeout, as we have already spent time */
+ if (elapsed > 0 && elapsed < cbd->ev.timeout) {
+ cbd->ev.timeout -= elapsed;
+ }
if (what == EV_READ) {
if (cbd->ssl_conn) {