diff --git a/include/haproxy/backend.h b/include/haproxy/backend.h index 3fae24280..41ad4de6e 100644 --- a/include/haproxy/backend.h +++ b/include/haproxy/backend.h @@ -167,6 +167,12 @@ void set_backend_down(struct proxy *be); unsigned int gen_hash(const struct proxy* px, const char* key, unsigned long len); +/* Returns true if connection reuse is supported by backend. */ +static inline int be_supports_conn_reuse(const struct proxy *be) +{ + return be->mode == PR_MODE_HTTP || be->mode == PR_MODE_SPOP; +} + #endif /* _HAPROXY_BACKEND_H */ /* diff --git a/src/backend.c b/src/backend.c index d0c1b8077..6412eb2b8 100644 --- a/src/backend.c +++ b/src/backend.c @@ -1664,6 +1664,10 @@ int64_t be_calculate_conn_hash(struct server *srv, struct stream *strm, * conducted on session. This allows to use a connection not yet * labelled as safe under http-reuse safe policy. * + * This function should only be called for backends which supports connection + * reuse. It may be necessary to extend be_supports_conn_reuse() when + * implementing a new proxy mode. + * * Returns SF_ERR_NONE if a connection has been reused. The connection instance * can be retrieve via stconn. SF_ERR_RESOURCE is returned if no matching * connection found. SF_ERR_INTERNAL is used on internal error. @@ -1814,6 +1818,9 @@ int connect_server(struct stream *s) if (err != SRV_STATUS_OK) return SF_ERR_INTERNAL; + if (!be_supports_conn_reuse(s->be)) + goto skip_reuse; + /* disable reuse if websocket stream and the protocol to use is not the * same as the main protocol of the server. */ @@ -1904,6 +1911,7 @@ int connect_server(struct stream *s) } } + skip_reuse: /* no reuse or failed to reuse the connection above, pick a new one */ if (!srv_conn) { unsigned int total_conns;