relayd does this evil thing of replacing the output buffer of bufferevnt with another one. This makes it impossible to reopen connections. Instead just write out the output buffer when connecting to the backend and move on.
THis is needed to make HTTP keep-alive work better. -- :wq Claudio Index: relay.c =================================================================== RCS file: /cvs/src/usr.sbin/relayd/relay.c,v retrieving revision 1.228 diff -u -p -r1.228 relay.c --- relay.c 27 Nov 2017 03:40:04 -0000 1.228 +++ relay.c 27 Nov 2017 17:03:34 -0000 @@ -712,10 +712,11 @@ relay_connected(int fd, short sig, void "failed to allocate output buffer event", 0); return; } - evbuffer_free(bev->output); - bev->output = con->se_out.output; - if (bev->output == NULL) - fatal("%s: invalid output buffer", __func__); + /* write pending output buffer now */ + if (bufferevent_write_buffer(bev, con->se_out.output)) { + relay_abort_http(con, 500, strerror(errno), 0); + return; + } con->se_out.bev = bev; /* Initialize the TLS wrapper */ @@ -1698,7 +1699,7 @@ relay_close(struct rsession *con, const free(con->se_priv); if (con->se_in.bev != NULL) bufferevent_free(con->se_in.bev); - else if (con->se_in.output != NULL) + if (con->se_in.output != NULL) evbuffer_free(con->se_in.output); if (con->se_in.tls != NULL) tls_close(con->se_in.tls); @@ -1720,7 +1721,7 @@ relay_close(struct rsession *con, const if (con->se_out.bev != NULL) bufferevent_free(con->se_out.bev); - else if (con->se_out.output != NULL) + if (con->se_out.output != NULL) evbuffer_free(con->se_out.output); if (con->se_out.tls != NULL) tls_close(con->se_out.tls);