[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [Libevent-users] requests over HTTPS after server-side close



On Sun, Jan 25, 2015 at 02:47:50PM +0100, Steffen Christgau wrote:
> On 24.01.2015 23:29, Azat Khuzhin wrote:
> > Which version of libevent do you use? (If you have git commit hash --
> > that would be great).
> 
> For the tests in the original posting, I used 2.1.5-beta (as stated ;-))
> but also tried a recent clone of the github repo (last commit 0b49ae3)
> right now. Same effect. So both are affected.

Hi Steffen,

Could you test next patch?

[ Also available here:
https://github.com/azat/libevent/commit/be99ea4ffa5e7e77378f4f66c2763055ec64746b.patch ]

Cheers,
Azat.

commit be99ea4ffa5e7e77378f4f66c2763055ec64746b
Author: Azat Khuzhin <a3at.mail@xxxxxxxxx>
Date:   Sun Jan 25 19:16:12 2015 +0300

    openssl: fix reconnect after close
    
    When we install to -1 it means that fd is closed (see
    evhttp_connection_reset_() for example)
    And when it is installed from -1 to something more correct (positive
    number) it means that we must handle ssl handshake again, so do this.
    
    Reported-by: Steffen Christgau <mail@xxxxxxx>

diff --git a/bufferevent_openssl.c b/bufferevent_openssl.c
index b30f90f..80a751d 100644
--- a/bufferevent_openssl.c
+++ b/bufferevent_openssl.c
@@ -1266,10 +1266,15 @@ be_openssl_ctrl(struct bufferevent *bev,
     enum bufferevent_ctrl_op op, union bufferevent_ctrl_data *data)
 {
        struct bufferevent_openssl *bev_ssl = upcast(bev);
+       BIO *bio = SSL_get_wbio(bev_ssl->ssl);
+       int old_fd;
+
        switch (op) {
        case BEV_CTRL_SET_FD:
                if (bev_ssl->underlying)
                        return -1;
+               old_fd = BIO_get_fd(bio, NULL);
+
                {
                        BIO *bio;
                        bio = BIO_new_socket(data->fd, 0);
@@ -1278,6 +1283,11 @@ be_openssl_ctrl(struct bufferevent *bev,
                }
                if (data->fd == -1)
                        bev_ssl->fd_is_set = 0;
+               else if (old_fd < 0 && data->fd != -1) {
+                       /** Reconnect after close */
+                       bev_ssl->state = BUFFEREVENT_SSL_CONNECTING;
+                       SSL_set_connect_state(bev_ssl->ssl);
+               }
                if (bev_ssl->state == BUFFEREVENT_SSL_OPEN)
                        return set_open_callbacks(bev_ssl, data->fd);
                else {


***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.