haproxy/include/types
Willy Tarreau f79c8171b2 MAJOR: connection: add two new flags to indicate readiness of control/transport
Currently the control and transport layers of a connection are supposed
to be initialized when their respective pointers are not NULL. This will
not work anymore when we plan to reuse connections, because there is an
asymmetry between the accept() side and the connect() side :

  - on accept() side, the fd is set first, then the ctrl layer then the
    transport layer ; upon error, they must be undone in the reverse order,
    then the FD must be closed. The FD must not be deleted if the control
    layer was not yet initialized ;

  - on the connect() side, the fd is set last and there is no reliable way
    to know if it has been initialized or not. In practice it's initialized
    to -1 first but this is hackish and supposes that local FDs only will
    be used forever. Also, there are even less solutions for keeping trace
    of the transport layer's state.

Also it is possible to support delayed close() when something (eg: logs)
tracks some information requiring the transport and/or control layers,
making it even more difficult to clean them.

So the proposed solution is to add two flags to the connection :

  - CO_FL_CTRL_READY is set when the control layer is initialized (fd_insert)
    and cleared after it's released (fd_delete).

  - CO_FL_XPRT_READY is set when the control layer is initialized (xprt->init)
    and cleared after it's released (xprt->close).

The functions have been adapted to rely on this and not on the pointers
anymore. conn_xprt_close() was unused and dangerous : it did not close
the control layer (eg: the socket itself) but still marks the transport
layer as closed, preventing any future call to conn_full_close() from
finishing the job.

The problem comes from conn_full_close() in fact. It needs to close the
xprt and ctrl layers independantly. After that we're still having an issue :
we don't know based on ->ctrl alone whether the fd was registered or not.
For this we use the two new flags CO_FL_XPRT_READY and CO_FL_CTRL_READY. We
now rely on this and not on conn->xprt nor conn->ctrl anymore to decide what
remains to be done on the connection.

In order not to miss some flag assignments, we introduce conn_ctrl_init()
to initialize the control layer, register the fd using fd_insert() and set
the flag, and conn_ctrl_close() which unregisters the fd and removes the
flag, but only if the transport layer was closed.

Similarly, at the transport layer, conn_xprt_init() calls ->init and sets
the flag, while conn_xprt_close() checks the flag, calls ->close and clears
the flag, regardless xprt_ctx or xprt_st. This also ensures that the ->init
and the ->close functions are called only once each and in the correct order.
Note that conn_xprt_close() does nothing if the transport layer is still
tracked.

conn_full_close() now simply calls conn_xprt_close() then conn_full_close()
in turn, which do nothing if CO_FL_XPRT_TRACKED is set.

In order to handle the error path, we also provide conn_force_close() which
ignores CO_FL_XPRT_TRACKED and closes the transport and the control layers
in turns. All relevant instances of fd_delete() have been replaced with
conn_force_close(). Now we always know what state the connection is in and
we can expect to split its initialization.
2013-12-09 15:40:23 +01:00
..
acl.h MINOR: acl/pattern: use types different from int to clarify who does what. 2013-12-02 23:31:33 +01:00
arg.h MEDIUM: http: The redirect strings follows the log format rules. 2013-12-02 23:31:33 +01:00
auth.h
backend.h MEDIUM: backend: add support for the wt6 hash 2013-11-14 16:37:50 +01:00
capture.h
channel.h DOC: fix typo in comments 2013-10-01 09:49:21 +02:00
checks.h BUG/MINOR: checks: tcp-check actions are enums, not flags 2013-12-06 16:16:41 +01:00
compression.h MEDIUM: compression: use pool for comp_ctx 2012-11-21 01:56:47 +01:00
connection.h MAJOR: connection: add two new flags to indicate readiness of control/transport 2013-12-09 15:40:23 +01:00
counters.h MINOR: stats: report the total number of compressed responses per front/back 2012-11-24 14:54:13 +01:00
fd.h MAJOR: polling: remove unused callbacks from the poller struct 2012-11-11 21:02:34 +01:00
freq_ctr.h
global.h BUG/MEDIUM: unique_id: HTTP request counter must be unique! 2013-08-13 17:52:20 +02:00
hdr_idx.h
lb_chash.h
lb_fas.h
lb_fwlc.h
lb_fwrr.h
lb_map.h
listener.h MINOR: ssl: add support for the "alpn" bind keyword 2013-04-03 02:13:02 +02:00
log.h BUG/MINOR: log: make log-format, unique-id-format and add-header more independant 2012-12-28 09:51:00 +01:00
map.h MEDIUM: map: merge identical maps 2013-12-06 11:40:53 +01:00
obj_type.h MINOR: obj: introduce a new type appctx 2013-12-09 15:40:22 +01:00
pattern.h MINOR: acl/pattern: use types different from int to clarify who does what. 2013-12-02 23:31:33 +01:00
peers.h CLEANUP: Remove unused 'last_slowstart_change' field from struct peer 2013-11-19 08:04:59 +01:00
pipe.h
port_range.h
proto_http.h BUILD/MINOR: missing header file 2013-10-23 15:53:56 +02:00
proto_tcp.h MINOR: tcp: add new "close" action for tcp-response 2013-09-11 23:28:51 +02:00
protocol.h MEDIUM: protocol: implement a "drain" function in protocol layers 2013-06-10 20:33:23 +02:00
proxy.h MEDIUM: checks: add send/expect tcp based check 2013-12-06 11:50:47 +01:00
queue.h
sample.h MINOR: sample: add a private field to the struct sample_conv 2013-12-02 23:31:33 +01:00
server.h MEDIUM: checks: add send/expect tcp based check 2013-12-06 11:50:47 +01:00
session.h MEDIUM: session: attach incoming connection to target on embryonic sessions 2013-12-09 15:40:22 +01:00
signal.h
ssl_sock.h MEDIUM: ssl: improve crt-list format to support negation 2013-05-07 22:11:54 +02:00
stick_table.h MEDIUM: stick-tables: flush old entries upon soft-stop 2013-09-04 17:54:01 +02:00
stream_interface.h MAJOR: stream-int: stop using si->conn and use si->end instead 2013-12-09 15:40:22 +01:00
task.h
template.h