]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
net_reader: bail out on NNTP SOCKS connection failure
authorEric Wong <e@80x24.org>
Tue, 3 Oct 2023 06:43:45 +0000 (06:43 +0000)
committerEric Wong <e@80x24.org>
Tue, 3 Oct 2023 10:16:04 +0000 (10:16 +0000)
It takes some effort to get Net::NNTP and IO::Socket::Socks
to place nice together, but we don't want the setsockopt
call to fail on an undefined value.  So die with an error
that tries to show various possible error sources.

$SOCKS_ERROR is a special variable, so even using `//'
(defined-or) operator isn't enough to squelch warnings
about using it in its uninitialized state.

lib/PublicInbox/NetNNTPSocks.pm
lib/PublicInbox/NetReader.pm

index fcd2e58038266b4a3f77e09b349194d26981da62..5b15dd5959dbc52fafd718b009003464c44e3774 100644 (file)
@@ -17,16 +17,18 @@ sub new_socks {
        local %OPT = map {;
                defined($opt{$_}) ? ($_ => $opt{$_}) : ()
        } @SOCKS_KEYS;
-       Net::NNTP->new(%opt); # this calls our new() below:
+       no warnings 'uninitialized'; # needed for $SOCKS_ERROR
+       Net::NNTP->new(%opt) // die "errors: \$!=$! SOCKS=",
+                               eval('$IO::Socket::Socks::SOCKS_ERROR // ""'),
+                               ', SSL=',
+                               (eval('IO::Socket::SSL->errstr')  // ''), "\n";
 }
 
 # called by Net::NNTP->new
 sub new {
        my ($self, %opt) = @_;
        @OPT{qw(ConnectAddr ConnectPort)} = @opt{qw(PeerAddr PeerPort)};
-       my $ret = $self->SUPER::new(%OPT) or
-               die 'SOCKS error: '.eval('$IO::Socket::Socks::SOCKS_ERROR');
-       $ret;
+       $self->SUPER::new(%OPT);
 }
 
 1;
index 6802fa72c5332871b979c24207ad442479bbd128..32e4c20ff7577e8825c2b1fe6db766b2615e0a52 100644 (file)
@@ -180,8 +180,7 @@ sub nn_new ($$$) {
        if (defined $nn_arg->{ProxyAddr}) {
                require PublicInbox::NetNNTPSocks;
                $nn_arg->{SocksDebug} = 1 if $nn_arg->{Debug};
-               eval { $nn = PublicInbox::NetNNTPSocks->new_socks(%$nn_arg) };
-               die "E: <$uri> $@\n" if $@;
+               $nn = PublicInbox::NetNNTPSocks->new_socks(%$nn_arg) or return;
        } else {
                $nn = Net::NNTP->new(%$nn_arg) or return;
        }