From: Eric Wong Date: Thu, 3 Apr 2025 08:46:17 +0000 (+0000) Subject: ds: close: always call SSL_close on TLS sockets X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=37a3ec73725f8b6c4c89b1ef12e8ebfafb7fb250;p=thirdparty%2Fpublic-inbox.git ds: close: always call SSL_close on TLS sockets 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. --- diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm index bb45ec99e..a0cb293e7 100644 --- a/lib/PublicInbox/DS.pm +++ b/lib/PublicInbox/DS.pm @@ -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 diff --git a/lib/PublicInbox/IMAP.pm b/lib/PublicInbox/IMAP.pm index c3b0b41e5..807e9c09d 100644 --- a/lib/PublicInbox/IMAP.pm +++ b/lib/PublicInbox/IMAP.pm @@ -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; } diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm index 07d86d603..5acaea0f6 100644 --- a/lib/PublicInbox/NNTP.pm +++ b/lib/PublicInbox/NNTP.pm @@ -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; } diff --git a/lib/PublicInbox/POP3.pm b/lib/PublicInbox/POP3.pm index 067720696..6d24b17c6 100644 --- a/lib/PublicInbox/POP3.pm +++ b/lib/PublicInbox/POP3.pm @@ -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; }