Skip to content

Commit

Permalink
be: fix with filtered bufferevents and connect() without EAGAIN
Browse files Browse the repository at this point in the history
With filtered bufferevents (i.e. not real one, that have socket), we can
trigger incorrect callback in this case. Let's look at example with http
and bufferevent_openssl_filter_new():
- bev = bufferevent_openssl_filter_new()
- http layer trying to connect() to localhost with bev
  # at this time, bev have writecb/readcb NULL but ev_write/ev_read has
  # timeout with 45 secs, default HTTP connect timeout
- and when connect() retruns without EAGAIN (BSD'ism) we called
  event_active() before (with EV_WRITE), and this will call ev_write
  timeout only, while it is more correct to act on bufferevent instead
  of plain event, so let's trigger EV_WRITE for bufferevent which will
  do the job (and let's do this deferred).

Fixes: http/https_simple # under solaris
  • Loading branch information
azat committed Jan 19, 2017
1 parent 09b6201 commit 9a0a3a3
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions bufferevent_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ bufferevent_writecb(evutil_socket_t fd, short event, void *arg)
/* we need to fake the error if the connection was refused
* immediately - usually connection to localhost on BSD */
if (bufev_p->connection_refused) {
bufev_p->connection_refused = 0;
c = -1;
bufev_p->connection_refused = 0;
c = -1;
}

if (c == 0)
Expand Down Expand Up @@ -438,13 +438,12 @@ bufferevent_socket_connect(struct bufferevent *bev,
/* The connect succeeded already. How very BSD of it. */
result = 0;
bufev_p->connecting = 1;
event_active(&bev->ev_write, EV_WRITE, 1);
bufferevent_trigger_nolock_(bev, EV_WRITE, BEV_OPT_DEFER_CALLBACKS);
} else {
/* The connect failed already. How very BSD of it. */
bufev_p->connection_refused = 1;
bufev_p->connecting = 1;
result = 0;
event_active(&bev->ev_write, EV_WRITE, 1);
bufferevent_run_eventcb_(bev, BEV_EVENT_ERROR, BEV_OPT_DEFER_CALLBACKS);
bufferevent_disable(bev, EV_WRITE|EV_READ);
}

goto done;
Expand Down

0 comments on commit 9a0a3a3

Please sign in to comment.