Changeset 816

Show
Ignore:
Timestamp:
08/25/08 04:49:49 (3 months ago)
Author:
brong
Message:

avoid ssl_eof error on SSL_WANT_READ and friends

http://codereview.appspot.com/2341

---

Incrementing a counter on empty SSL reads is not the correct way to determine
ssl_eof
(http://code.sixapart.com/trac/djabberd/changeset/758)

Instead we should check the error code to see if it is one of the SSL errors for
which we are supposed to retry(
http://www.openssl.org/docs/ssl/SSL_get_error.html)

---

I've been testing this for a couple of weeks at FastMail now, and it's stopped
the random disconection errors that some of our SSL users were having. Also,
nobody on the mailing list objected

-- Bron

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/DJabberd/lib/DJabberd/Connection.pm

    r786 r816  
    505505            # wasn't enough of an SSL packet for OpenSSL/etc to return 
    506506            # any unencrypted data back to us. 
    507             if (++$self->{'ssl_empty_read_ct'} >= 10) { 
     507            # We call 'actual_error_on_empty_read' to avoid counting 
     508            # SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE as 'actual' errors 
     509            my $err = DJabberd::Stanza::StartTLS->actual_error_on_empty_read($ssl); 
     510            if($err && ++$self->{'ssl_empty_read_ct'} >= 10) { 
     511                $self->log->warn("SSL Read error: $err (assuming ssl_eof)"); 
    508512                $self->close('ssl_eof'); 
    509513            } 
  • trunk/DJabberd/lib/DJabberd/Stanza/StartTLS.pm

    r463 r816  
    1010use constant SSL_ERROR_WANT_READ     => 2; 
    1111use constant SSL_ERROR_WANT_WRITE    => 3; 
     12use constant SSL_ERROR_WANT_CONNECT  => 4; 
     13use constant SSL_ERROR_WANT_ACCEPT   => 5; 
    1214 
    1315sub on_recv_from_server { &process } 
     
    6870} 
    6971 
     72sub actual_error_on_empty_read { 
     73    my ($class, $ssl) = @_; 
     74    my $err = Net::SSLeay::get_error($ssl, -1); 
     75    if ($err == SSL_ERROR_WANT_READ ||  
     76        $err == SSL_ERROR_WANT_WRITE ||  
     77        $err == SSL_ERROR_WANT_CONNECT ||  
     78        $err == SSL_ERROR_WANT_ACCEPT) { 
     79        # Not an actual error, SSL is busy doing something like renegotiating encryption 
     80        # just try again next time 
     81        return 0; 
     82    } 
     83    # This is actually an error (return the SSL err code) 
     84    # unlike the 'no-op' WANT_READ and WANT_WRITE 
     85    return $err; 
     86} 
     87 
     88 
    7089sub danga_socket_writerfunc { 
    7190    my ($class, $conn) = @_;