]> granicus.if.org Git - libevent/commit
http: fix connection retries when there more then one request for connection
authorAzat Khuzhin <azat@libevent.org>
Fri, 7 Dec 2018 18:46:27 +0000 (21:46 +0300)
committerAzat Khuzhin <azat@libevent.org>
Sat, 2 Feb 2019 12:18:06 +0000 (15:18 +0300)
commitd30e7bbac9f1669eab601c3937debb08fc01fe45
tree685682e5f12ecf2e67e8331f0a851e0ef3b4736b
parenta8155c62d899549344f9571597a24b0207dffdf3
http: fix connection retries when there more then one request for connection

We should not attemp to establishe the connection if there is retry
timer active, since otherwise there will be a bug.

Imagine next situation:
  con = evhttp_connection_base_new()
  evhttp_connection_set_retries(con, 2)
  req = evhttp_request_new()
  evhttp_make_request(con, req, ...)
  # failed during connecting, and timer for 2 second scheduler (retry_ev)

Then another request scheduled for this evcon:
  evhttp_make_request(con, req, ...)
  # got request from server,
  # and now it tries to read the response from the server
  # (req.kind == EVHTTP_RESPONSE)
  #
  # but at this point retry_ev scheduled,
  # and it schedules the connect again,
  # and after the connect will succeeed, it will pick request with
  # EVHTTP_RESPONSE for sending and this is completelly wrong and will
  # fail in evhttp_make_header_response() since there is no
  # "http_server" for this evcon

This was a long standing issue, that I came across few years ago
firstly, bad only now I had time to dig into it (but right now it was
pretty simple, by limiting amount of CPU for the process and using rr
for debug to go back and forth).

(cherry picked from commit f3f7aa5afff2c0be4a1a299a1a7d0a64558abc23)
http.c