]> Sergey Matveev's repositories - public-inbox.git/commitdiff
tls: epollbit: account for miscellaneous OpenSSL errors
authorEric Wong <e@80x24.org>
Fri, 30 Oct 2020 02:13:58 +0000 (02:13 +0000)
committerEric Wong <e@80x24.org>
Sat, 26 Dec 2020 19:37:46 +0000 (19:37 +0000)
Apparently they happen (triggered by my -imapd instance), so
bail out by closing the underlying socket rather than stopping
the event loop and daemon process.

(cherry picked from commit c51c22c349529d9c377160abcc7961a6ca7b7d5c)

lib/PublicInbox/DS.pm
lib/PublicInbox/HTTP.pm
lib/PublicInbox/IMAP.pm
lib/PublicInbox/NNTP.pm
lib/PublicInbox/TLS.pm

index d0caa5e73102f13ea27bf455e242b19cbb72220e..a02b3bb78641bd12254e718c3344a2bfef1801de 100644 (file)
@@ -433,7 +433,8 @@ next_buf:
                         goto next_buf;
                     }
                 } elsif ($! == EAGAIN) {
                         goto next_buf;
                     }
                 } elsif ($! == EAGAIN) {
-                    epwait($sock, epbit($sock, EPOLLOUT) | EPOLLONESHOT);
+                    my $ev = epbit($sock, EPOLLOUT) or return $self->close;
+                    epwait($sock, $ev | EPOLLONESHOT);
                     return 0;
                 } else {
                     return $self->close;
                     return 0;
                 } else {
                     return $self->close;
@@ -469,7 +470,8 @@ sub do_read ($$$;$) {
     # common for clients to break connections without warning,
     # would be too noisy to log here:
     if ($! == EAGAIN) {
     # common for clients to break connections without warning,
     # would be too noisy to log here:
     if ($! == EAGAIN) {
-        epwait($sock, epbit($sock, EPOLLIN) | EPOLLONESHOT);
+        my $ev = epbit($sock, EPOLLIN) or return $self->close;
+        epwait($sock, $ev | EPOLLONESHOT);
         rbuf_idle($self, $rbuf);
         0;
     } else {
         rbuf_idle($self, $rbuf);
         0;
     } else {
@@ -543,7 +545,8 @@ sub write {
             return 1 if $written == $to_write;
             requeue($self); # runs: event_step -> flush_write
         } elsif ($! == EAGAIN) {
             return 1 if $written == $to_write;
             requeue($self); # runs: event_step -> flush_write
         } elsif ($! == EAGAIN) {
-            epwait($sock, epbit($sock, EPOLLOUT) | EPOLLONESHOT);
+            my $ev = epbit($sock, EPOLLOUT) or return $self->close;
+            epwait($sock, $ev | EPOLLONESHOT);
             $written = 0;
         } else {
             return $self->close;
             $written = 0;
         } else {
             return $self->close;
@@ -596,7 +599,8 @@ sub accept_tls_step ($) {
     my $sock = $self->{sock} or return;
     return 1 if $sock->accept_SSL;
     return $self->close if $! != EAGAIN;
     my $sock = $self->{sock} or return;
     return 1 if $sock->accept_SSL;
     return $self->close if $! != EAGAIN;
-    epwait($sock, PublicInbox::TLS::epollbit() | EPOLLONESHOT);
+    my $ev = PublicInbox::TLS::epollbit() or return $self->close;
+    epwait($sock, $ev | EPOLLONESHOT);
     unshift(@{$self->{wbuf}}, \&accept_tls_step); # autovivifies
     0;
 }
     unshift(@{$self->{wbuf}}, \&accept_tls_step); # autovivifies
     0;
 }
@@ -607,7 +611,8 @@ sub shutdn_tls_step ($) {
     my $sock = $self->{sock} or return;
     return $self->close if $sock->stop_SSL(SSL_fast_shutdown => 1);
     return $self->close if $! != EAGAIN;
     my $sock = $self->{sock} or return;
     return $self->close if $sock->stop_SSL(SSL_fast_shutdown => 1);
     return $self->close if $! != EAGAIN;
-    epwait($sock, PublicInbox::TLS::epollbit() | EPOLLONESHOT);
+    my $ev = PublicInbox::TLS::epollbit() or return $self->close;
+    epwait($sock, $ev | EPOLLONESHOT);
     unshift(@{$self->{wbuf}}, \&shutdn_tls_step); # autovivifies
     0;
 }
     unshift(@{$self->{wbuf}}, \&shutdn_tls_step); # autovivifies
     0;
 }
index 5844ef440f1e8dd324ce6b67401de7c99e696c8e..88020ae82438375e42a0854b6c6ae2c4defe2c89 100644 (file)
@@ -70,7 +70,7 @@ sub new ($$$) {
        my $wbuf;
        if ($sock->can('accept_SSL') && !$sock->accept_SSL) {
                return CORE::close($sock) if $! != EAGAIN;
        my $wbuf;
        if ($sock->can('accept_SSL') && !$sock->accept_SSL) {
                return CORE::close($sock) if $! != EAGAIN;
-               $ev = PublicInbox::TLS::epollbit();
+               $ev = PublicInbox::TLS::epollbit() or return CORE::close($sock);
                $wbuf = [ \&PublicInbox::DS::accept_tls_step ];
        }
        $self->{wbuf} = $wbuf if $wbuf;
                $wbuf = [ \&PublicInbox::DS::accept_tls_step ];
        }
        $self->{wbuf} = $wbuf if $wbuf;
index d93792acf7ae94406d54999ecc1cf11c01510713..c9a024d6024c75540139a0a8893365cfa0998877 100644 (file)
@@ -115,7 +115,7 @@ sub new ($$$) {
        my $wbuf;
        if ($sock->can('accept_SSL') && !$sock->accept_SSL) {
                return CORE::close($sock) if $! != EAGAIN;
        my $wbuf;
        if ($sock->can('accept_SSL') && !$sock->accept_SSL) {
                return CORE::close($sock) if $! != EAGAIN;
-               $ev = PublicInbox::TLS::epollbit();
+               $ev = PublicInbox::TLS::epollbit() or return CORE::close($sock);
                $wbuf = [ \&PublicInbox::DS::accept_tls_step, \&greet ];
        }
        $self->SUPER::new($sock, $ev | EPOLLONESHOT);
                $wbuf = [ \&PublicInbox::DS::accept_tls_step, \&greet ];
        }
        $self->SUPER::new($sock, $ev | EPOLLONESHOT);
index 88fe2bb03a0797e424224771d8eab5e2c411784f..102ef42cf4455d8e4035b288172f19d693f85901 100644 (file)
@@ -53,7 +53,7 @@ sub new ($$$) {
        my $wbuf;
        if ($sock->can('accept_SSL') && !$sock->accept_SSL) {
                return CORE::close($sock) if $! != EAGAIN;
        my $wbuf;
        if ($sock->can('accept_SSL') && !$sock->accept_SSL) {
                return CORE::close($sock) if $! != EAGAIN;
-               $ev = PublicInbox::TLS::epollbit();
+               $ev = PublicInbox::TLS::epollbit() or return CORE::close($sock);
                $wbuf = [ \&PublicInbox::DS::accept_tls_step, \&greet ];
        }
        $self->SUPER::new($sock, $ev | EPOLLONESHOT);
                $wbuf = [ \&PublicInbox::DS::accept_tls_step, \&greet ];
        }
        $self->SUPER::new($sock, $ev | EPOLLONESHOT);
index 0f838e25792c3ba861c2dd7518c74dc8d583b18c..86e6331d5ea2df97f7cd4c22ba9898f83b275cbd 100644 (file)
@@ -6,6 +6,7 @@ package PublicInbox::TLS;
 use strict;
 use IO::Socket::SSL;
 use PublicInbox::Syscall qw(EPOLLIN EPOLLOUT);
 use strict;
 use IO::Socket::SSL;
 use PublicInbox::Syscall qw(EPOLLIN EPOLLOUT);
+use Carp qw(carp);
 
 sub err () { $SSL_ERROR }
 
 
 sub err () { $SSL_ERROR }
 
@@ -13,7 +14,8 @@ sub err () { $SSL_ERROR }
 sub epollbit () {
        return EPOLLIN if $SSL_ERROR == SSL_WANT_READ;
        return EPOLLOUT if $SSL_ERROR == SSL_WANT_WRITE;
 sub epollbit () {
        return EPOLLIN if $SSL_ERROR == SSL_WANT_READ;
        return EPOLLOUT if $SSL_ERROR == SSL_WANT_WRITE;
-       die "unexpected SSL error: $SSL_ERROR";
+       carp "unexpected SSL error: $SSL_ERROR";
+       undef;
 }
 
 1;
 }
 
 1;