}
/* Force to close the connection whatever the tracking state. This is mainly
- * used on the error path where the tracking does not make sense.
+ * used on the error path where the tracking does not make sense, or to kill
+ * an idle connection we want to abort immediately.
*/
static inline void conn_force_close(struct connection *conn)
{
applet->release(si);
}
+/* Try to allocate a new connection and assign it to the interface. If
+ * a connection was previously allocated and the <reuse> flag is set,
+ * it is returned unmodified. Otherwise it is reset.
+ */
/* Returns the stream interface's existing connection if one such already
* exists, or tries to allocate and initialize a new one which is then
* assigned to the stream interface.
*/
-static inline struct connection *si_alloc_conn(struct stream_interface *si)
+static inline struct connection *si_alloc_conn(struct stream_interface *si, int reuse)
{
struct connection *conn;
*/
if (si->end) {
conn = objt_conn(si->end);
- if (conn)
+ if (conn) {
+ if (!reuse) {
+ conn_force_close(conn);
+ conn_init(conn);
+ }
return conn;
+ }
/* it was an applet then */
si_release_endpoint(si);
}
int connect_server(struct session *s)
{
struct connection *cli_conn;
- struct connection *srv_conn = si_alloc_conn(s->req->cons);
+ struct connection *srv_conn = si_alloc_conn(s->req->cons, 0);
struct server *srv;
int err;
if ((s->be->options & PR_O_HTTP_PROXY) && !(s->flags & SN_ADDR_SET)) {
struct connection *conn;
- if (unlikely((conn = si_alloc_conn(req->cons)) == NULL)) {
+ /* Note that for now we don't reuse existing proxy connections */
+ if (unlikely((conn = si_alloc_conn(req->cons, 0)) == NULL)) {
txn->req.msg_state = HTTP_MSG_ERROR;
txn->status = 500;
req->analysers = 0;