diff options
author | Christopher Faulet <cfaulet@haproxy.com> | 2023-02-27 16:08:31 +0100 |
---|---|---|
committer | Christopher Faulet <cfaulet@haproxy.com> | 2023-02-27 17:45:45 +0100 |
commit | 85e568f594fa87f2494b40e749ab8aa5a7fe54a3 (patch) | |
tree | 6fcd2bd8f01929af69b4c6f69d7ca2c4bd77b758 | |
parent | 3bbd2baab3bbbc2234b8e252f5e0cd311e490395 (diff) | |
download | haproxy-85e568f594fa87f2494b40e749ab8aa5a7fe54a3.tar.gz |
MINOR: stream: Handle stream's timeouts in a dedicated function
This will be mandatory to be able to handle stream's timeouts before exiting
process_stream(). So, to not duplicate code, all this stuff is moved in a
dedicated function.
-rw-r--r-- | src/stream.c | 76 |
1 files changed, 41 insertions, 35 deletions
diff --git a/src/stream.c b/src/stream.c index 4596fa6aa..a8a8816ae 100644 --- a/src/stream.c +++ b/src/stream.c @@ -1566,6 +1566,46 @@ static void stream_update_both_sc(struct stream *s) } } +/* check SC and channel timeouts, and close the corresponding stream connectors + * for future reads or writes. + * Note: this will also concern upper layers but we do not touch any other + * flag. We must be careful and correctly detect state changes when calling + * them. + */ +static void stream_handle_timeouts(struct stream *s) +{ + stream_check_conn_timeout(s); + + sc_check_timeouts(s->scf); + channel_check_timeout(&s->req); + if (unlikely((s->req.flags & (CF_SHUTW|CF_WRITE_TIMEOUT)) == CF_WRITE_TIMEOUT)) { + s->scb->flags |= SC_FL_NOLINGER; + sc_shutw(s->scb); + } + + if (unlikely((s->req.flags & (CF_SHUTR|CF_READ_TIMEOUT)) == CF_READ_TIMEOUT)) { + if (s->scf->flags & SC_FL_NOHALF) + s->scf->flags |= SC_FL_NOLINGER; + sc_shutr(s->scf); + } + + sc_check_timeouts(s->scb); + channel_check_timeout(&s->res); + if (unlikely((s->res.flags & (CF_SHUTW|CF_WRITE_TIMEOUT)) == CF_WRITE_TIMEOUT)) { + s->scf->flags |= SC_FL_NOLINGER; + sc_shutw(s->scf); + } + + if (unlikely((s->res.flags & (CF_SHUTR|CF_READ_TIMEOUT)) == CF_READ_TIMEOUT)) { + if (s->scb->flags & SC_FL_NOHALF) + s->scb->flags |= SC_FL_NOLINGER; + sc_shutr(s->scb); + } + + if (HAS_FILTERS(s)) + flt_stream_check_timeouts(s); +} + /* if the current task's wake_date was set, it's being profiled, thus we may * report latencies and CPU usages in logs, so it's desirable to update the * latency when entering process_stream(). @@ -1727,41 +1767,7 @@ struct task *process_stream(struct task *t, void *context, unsigned int state) * stream connectors when their timeouts have expired. */ if (unlikely(s->pending_events & TASK_WOKEN_TIMER)) { - stream_check_conn_timeout(s); - - /* check SC and channel timeouts, and close the corresponding stream connectors - * for future reads or writes. Note: this will also concern upper layers - * but we do not touch any other flag. We must be careful and correctly - * detect state changes when calling them. - */ - sc_check_timeouts(scf); - channel_check_timeout(req); - if (unlikely((req->flags & (CF_SHUTW|CF_WRITE_TIMEOUT)) == CF_WRITE_TIMEOUT)) { - scb->flags |= SC_FL_NOLINGER; - sc_shutw(scb); - } - - if (unlikely((req->flags & (CF_SHUTR|CF_READ_TIMEOUT)) == CF_READ_TIMEOUT)) { - if (scf->flags & SC_FL_NOHALF) - scf->flags |= SC_FL_NOLINGER; - sc_shutr(scf); - } - - sc_check_timeouts(scb); - channel_check_timeout(res); - if (unlikely((res->flags & (CF_SHUTW|CF_WRITE_TIMEOUT)) == CF_WRITE_TIMEOUT)) { - scf->flags |= SC_FL_NOLINGER; - sc_shutw(scf); - } - - if (unlikely((res->flags & (CF_SHUTR|CF_READ_TIMEOUT)) == CF_READ_TIMEOUT)) { - if (scb->flags & SC_FL_NOHALF) - scb->flags |= SC_FL_NOLINGER; - sc_shutr(scb); - } - - if (HAS_FILTERS(s)) - flt_stream_check_timeouts(s); + stream_handle_timeouts(s); /* Once in a while we're woken up because the task expires. But * this does not necessarily mean that a timeout has been reached. |