]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
ds: close: always call SSL_close on TLS sockets
authorEric Wong <e@80x24.org>
Thu, 3 Apr 2025 08:46:17 +0000 (08:46 +0000)
committerEric Wong <e@80x24.org>
Fri, 4 Apr 2025 19:52:44 +0000 (19:52 +0000)
Instead of relying on the explicit ->shutdn API, just
use the overloaded ->close so $env->{'psgix.io'} callers
can use it directly.  This makes it easier to ensure
proper shutdown so SSL session reuse can be a possiblity.

lib/PublicInbox/DS.pm
lib/PublicInbox/IMAP.pm
lib/PublicInbox/NNTP.pm
lib/PublicInbox/POP3.pm

index bb45ec99ece2628744addc194e292e5ff2819698..a0cb293e78964cb26ecbac4264e53eb8871546b1 100644 (file)
@@ -364,7 +364,7 @@ sub requeue ($) { push @$nextq, $_[0] } # autovivifies
 
 # drop the IO::Handle ref, true if successful, false if not (or already dropped)
 # (this is closer to CORE::close than Danga::Socket::close)
-sub close {
+sub ds_close ($) {
        my ($self) = @_;
        my $sock = delete $self->{sock} or return;
 
@@ -625,19 +625,19 @@ sub accept_tls_step ($) {
 sub shutdn_tls_step ($) {
        my ($self) = @_;
        my $sock = $self->{sock} or return;
-       return $self->close if $sock->stop_SSL(SSL_fast_shutdown => 1);
-       return $self->close if $! != EAGAIN;
-       my $ev = PublicInbox::TLS::epollbit() or return $self->close;
+       return ds_close($self) if $sock->stop_SSL(SSL_fast_shutdown => 1) ||
+                               $! != EAGAIN;
+       my $ev = PublicInbox::TLS::epollbit() or return ds_close($self);
        epwait $sock, $ev | EPOLLONESHOT;
        unshift @{$self->{wbuf}}, \&shutdn_tls_step; # autovivifies
 }
 
 # don't bother with shutdown($sock, 2), we don't fork+exec w/o CLOEXEC
 # or fork w/o exec, so no inadvertent socket sharing
-sub shutdn ($) {
+sub close {
        my ($self) = @_;
        my $sock = $self->{sock} or return;
-       $sock->can('stop_SSL') ? shutdn_tls_step $self : $self->close;
+       $sock->can('stop_SSL') ? shutdn_tls_step($self) : ds_close($self);
 }
 
 sub dflush {} # overridden by DSdeflate
index c3b0b41e5b9aed57d5b301b7d7fdacf43ddad7d9..807e9c09dfb069aea8a7826766aba572085cd53e 100644 (file)
@@ -151,7 +151,7 @@ sub cmd_logout ($$) {
        my ($self, $tag) = @_;
        delete $self->{-idle_tag};
        $self->write(\"* BYE logging out\r\n$tag OK Logout done\r\n");
-       $self->shutdn; # PublicInbox::DS::shutdn
+       $self->close;
        undef;
 }
 
index 07d86d6032a3454360409cb03e5725cee979b311..5acaea0f6a2ff5ebb949f7a1bf64b9b96924d1d8 100644 (file)
@@ -386,7 +386,7 @@ sub cmd_post ($) {
 sub cmd_quit ($) {
        my ($self) = @_;
        $self->write(\"205 closing connection - goodbye!\r\n");
-       $self->shutdn;
+       $self->close;
        undef;
 }
 
index 067720696e4c2b0421b3d22930a4988dfcf8bcbe..6d24b17c6c00aec1e581e533cc6d1fdfab618229 100644 (file)
@@ -370,7 +370,7 @@ UPDATE users SET last_seen = ? WHERE user_id = ?
                $self->{pop3d}->unlock_mailbox($self);
        }
        $self->write(\"+OK public-inbox POP3 server signing off\r\n");
-       $self->shutdn;
+       $self->close;
        undef;
 }