From: Olivier Houchard Date: Fri, 18 Oct 2019 11:56:40 +0000 (+0200) Subject: BUG/MEDIUM: mux_pt: Don't destroy the connection if we have a stream attached. X-Git-Tag: v2.1-dev3~49 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ea510fc5e7cf8ead040253869160b0d2266ce65f;p=thirdparty%2Fhaproxy.git BUG/MEDIUM: mux_pt: Don't destroy the connection if we have a stream attached. There's a small window where the mux_pt tasklet may be woken up, and thus mux_pt_io_cb() get scheduled, and then the connection is attached to a new stream. If this happen, don't do anything, and just let the stream know by calling its wake method. If the connection had an error, the stream should take care of destroying it by calling the detach method. This should be backported to 2.0 and 1.9. --- diff --git a/src/mux_pt.c b/src/mux_pt.c index a86cbefd92..da35a8e239 100644 --- a/src/mux_pt.c +++ b/src/mux_pt.c @@ -50,6 +50,21 @@ static struct task *mux_pt_io_cb(struct task *t, void *tctx, unsigned short stat { struct mux_pt_ctx *ctx = tctx; + if (ctx->cs) { + /* There's a small race condition. + * mux_pt_io_cb() is only supposed to be called if we have no + * stream attached. However, maybe the tasklet got woken up, + * and this connection was then attached to a new stream. + * If this happened, just call the wake method. It is probably + * not needed, because the stream probably subscribed to + * receive events, but that way we'll be sure the event got + * noticed, and if we had any error on the connection, we will + * let the stream call the detach method to destroy it. + */ + if (ctx->cs->data_cb->wake) + ctx->cs->data_cb->wake(ctx->cs); + return NULL; + } conn_sock_drain(ctx->conn); if (ctx->conn->flags & (CO_FL_ERROR | CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH)) mux_pt_destroy(ctx);