BUG/MAJOR: stream-int: do not depend on connection flags to detect connection
authorWilly Tarreau <w@1wt.eu>
Sat, 18 Mar 2017 16:11:37 +0000 (17:11 +0100)
committerWilly Tarreau <w@1wt.eu>
Sun, 19 Mar 2017 11:00:04 +0000 (12:00 +0100)
commit52821e27376f89b41167565b01d975f47266284c
treeb03883004cdee286aea875e181c689ece0c77841
parentd78c0fa0fb32b27c49279c8fdb6e76bb6a01602f
BUG/MAJOR: stream-int: do not depend on connection flags to detect connection

Recent fix 7bf3fa3 ("BUG/MAJOR: connection: update CO_FL_CONNECTED before
calling the data layer") marked an end to a fragile situation where the
absence of CO_FL_{CONNECTED,L4,L6}* flags is used to mark the completion
of a connection setup. The problem is that by setting the CO_FL_CONNECTED
flag earlier, we can indeed call the ->wake() function from conn_fd_handler
but the stream-interface's wake function needs to see CO_FL_CONNECTED unset
to detect that a connection has just been established, so if there's no
pending data in the buffer, the connection times out. The other ->wake()
functions (health checks and idle connections) don't do this though.

So instead of trying to detect a subtle change in connection flags,
let's simply rely on the stream-interface's state and validate that the
connection is properly established and that handshakes are completed
before reporting the WRITE_NULL indicating that a pending connection was
just completed.

This patch passed all tests of handshake and non-handshake combinations,
with synchronous and asynchronous connect() and should be safe for backport
to 1.7, 1.6 and 1.5 when the fix above is already present.
src/stream_interface.c