From: Aurelien DARRAGON Date: Tue, 23 Jul 2024 15:16:58 +0000 (+0200) Subject: MEDIUM: sink: don't set NOLINGER flag on the outgoing stream interface X-Git-Tag: v3.1-dev4~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0821460e3f7c8212340507c86e193c4bed210789;p=thirdparty%2Fhaproxy.git MEDIUM: sink: don't set NOLINGER flag on the outgoing stream interface Given that sink applets are responsible for conveying messages from the ring to the tcp server endpoint, there are no protocol timeout or errors expected there, it is an unidirectional flow of data over TCP. As such, NOLINGER flag which was inherited from peers applet, see dbd026792 ("BUG/MEDIUM: peers: set NOLINGER on the outgoing stream interface") is not desirable under sink context: The reason why we have the NOLINGER flag set is to ensure the connection is closed right away and avoid 60s TIME_WAIT delay on closed sockets. The downside is that messages sent right before closing the socket are not guaranteed to make it to the server because closing with NOLINGER flag set will result in RST packet being emitted right away, which could prevent in-flight messages from being properly delivered. Unlike peers applets, the only cases were sink applets are expected to close the connection are upon unexpected error or upon stopping, which are relatively rare events. Thanks to previous commit, ERROR flag is already set in case of error, so the use of NOLINGER is not mandatory for the RST to be sent. Now for the stopping case, it only happens once in the process lifetime so it's acceptable to close the socket using EOS+EOI flags without the NOLINGER option set. So in our case, it is preferable to ensure messages get properly delivered knowning that closed sockets should be piling up in TIME_WAIT, this means removing the NOLINGER flag on the outgoing stream interface for sink applets. It is a prerequisite for upcoming patches in order to cleanly shut the applet during runtime without risking to send the RST packet before all pending messages were sent to the endpoint. --- diff --git a/src/sink.c b/src/sink.c index d935f49a82..8cc8acf242 100644 --- a/src/sink.c +++ b/src/sink.c @@ -465,7 +465,7 @@ static int sink_forward_session_init(struct appctx *appctx) s = appctx_strm(appctx); s->scb->dst = addr; - s->scb->flags |= (SC_FL_RCV_ONCE|SC_FL_NOLINGER); + s->scb->flags |= (SC_FL_RCV_ONCE); s->target = &sft->srv->obj_type; s->flags = SF_ASSIGNED;