From 8f31009e47ce8ae52cd70fff54ce96f2b2148b3a Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Thu, 21 Aug 2025 16:27:42 +0200 Subject: [PATCH] BUG/MAJOR: stream: Remove READ/WRITE events on channels after analysers eval It is possible to miss a synchronous write event in process_stream() if the stream was woken up on a write event. In that case, it is possible to freeze the stream until the next I/O event or timeout. Concretely, the stream is woken up with CF_WRITE_EVENT on a channel. this flag is removed from the channel when we leave proces_stream(). But before leaving process_stream(), when a synchronous send is tried on this channel, the flag is removed and eventually set again on success. But this event is masked by the previous one, and the channel is not resync as it should be. To fix the bug, CF_READ_EVENT and CF_WRITE_EVENT flags are removed from a channel after the corresponding analysers evaluation. This way, we will be able to detect a successful synchronous send to restart analysers evaluation based on the new channel state. It is safe (or it should be) to do so becaues these flags are only used by analysers and tested to resync the stream inside process_stream(). It is a very old bug and I guess all versions are affected. It was observed on 2.9 and higher, and with the master/worker only. But it could affect any stream. It is tagged a MAJOR because this area is really sensitive to any change. This patch should fix the issue #3070. It should probably be backported to all stable versions, but only after a period of observation and with a special care because this area is really sensitive to changes. It is probably reasonnable to backport it as far as 3.0 and wait for older versions. Thanks to Valentine for its help on this issue ! (cherry picked from commit a498e527b412d8b66e27d2175bfad3101f6dbedb) Signed-off-by: Christopher Faulet (cherry picked from commit d065cdb03342b2eaee857cd261488bf14382f144) Signed-off-by: Christopher Faulet (cherry picked from commit 711e2d4ed0b0458dddd6f001c2d14ba76aa6931a) Signed-off-by: Christopher Faulet --- src/stream.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/stream.c b/src/stream.c index f3f64fb..ae4450a 100644 --- a/src/stream.c +++ b/src/stream.c @@ -2051,7 +2051,7 @@ struct task *process_stream(struct task *t, void *context, unsigned int state) rq_prod_last = scf->state; rq_cons_last = scb->state; - req->flags &= ~CF_WAKE_ONCE; + req->flags &= ~(CF_WAKE_ONCE|CF_READ_EVENT|CF_WRITE_EVENT); rqf_last = req->flags; scf_flags = (scf_flags & ~(SC_FL_EOS|SC_FL_ABRT_DONE|SC_FL_ABRT_WANTED)) | (scf->flags & (SC_FL_EOS|SC_FL_ABRT_DONE|SC_FL_ABRT_WANTED)); scb_flags = (scb_flags & ~(SC_FL_SHUT_DONE|SC_FL_SHUT_WANTED)) | (scb->flags & (SC_FL_SHUT_DONE|SC_FL_SHUT_WANTED)); @@ -2124,7 +2124,7 @@ struct task *process_stream(struct task *t, void *context, unsigned int state) rp_cons_last = scf->state; rp_prod_last = scb->state; - res->flags &= ~CF_WAKE_ONCE; + res->flags &= ~(CF_WAKE_ONCE|CF_READ_EVENT|CF_WRITE_EVENT); rpf_last = res->flags; scb_flags = (scb_flags & ~(SC_FL_EOS|SC_FL_ABRT_DONE|SC_FL_ABRT_WANTED)) | (scb->flags & (SC_FL_EOS|SC_FL_ABRT_DONE|SC_FL_ABRT_WANTED)); scf_flags = (scf_flags & ~(SC_FL_SHUT_DONE|SC_FL_SHUT_WANTED)) | (scf->flags & (SC_FL_SHUT_DONE|SC_FL_SHUT_WANTED)); -- 1.7.10.4