]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: sink: don't set NOLINGER flag on the outgoing stream interface
authorAurelien DARRAGON <adarragon@haproxy.com>
Tue, 23 Jul 2024 15:16:58 +0000 (17:16 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Wed, 24 Jul 2024 15:58:58 +0000 (17:58 +0200)
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.

src/sink.c

index d935f49a8273a7fdf284aa073a019fcc26542797..8cc8acf242ddae115c08cf7cd50c40dbfc904ccf 100644 (file)
@@ -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;