unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 1/8] net_reader: bail out on NNTP SOCKS connection failure
Date: Tue,  3 Oct 2023 06:43:45 +0000	[thread overview]
Message-ID: <20231003064352.2902298-2-e@80x24.org> (raw)
In-Reply-To: <20231003064352.2902298-1-e@80x24.org>

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 | 10 ++++++----
 lib/PublicInbox/NetReader.pm    |  3 +--
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/lib/PublicInbox/NetNNTPSocks.pm b/lib/PublicInbox/NetNNTPSocks.pm
index fcd2e580..5b15dd59 100644
--- a/lib/PublicInbox/NetNNTPSocks.pm
+++ b/lib/PublicInbox/NetNNTPSocks.pm
@@ -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;
diff --git a/lib/PublicInbox/NetReader.pm b/lib/PublicInbox/NetReader.pm
index 6802fa72..32e4c20f 100644
--- a/lib/PublicInbox/NetReader.pm
+++ b/lib/PublicInbox/NetReader.pm
@@ -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;
 	}

  reply	other threads:[~2023-10-03  6:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-03  6:43 [PATCH 0/8] IMAP/NNTP client improvements Eric Wong
2023-10-03  6:43 ` Eric Wong [this message]
2023-10-03  6:43 ` [PATCH 2/8] net_reader: avoid IO::Socket::SSL 2.079..2.081 warning Eric Wong
2023-10-03  6:43 ` [PATCH 3/8] config: fix key-only truthy values with urlmatch Eric Wong
2023-10-03  6:43 ` [PATCH 4/8] net_reader: support imap.sslVerify + nntp.sslVerify Eric Wong
2023-10-03  6:43 ` [PATCH 5/8] lei: workers exit after they tell lei-daemon Eric Wong
2023-10-03  6:43 ` [PATCH 6/8] net_reader: process title reflects NNTP article Eric Wong
2023-10-03  6:43 ` [PATCH 7/8] xt/lei-onion-convert: test TLS + SOCKS Eric Wong
2023-10-03  6:43 ` [PATCH 8/8] net_reader: note glob support in .onion hint Eric Wong
2023-10-03  7:11 ` "SSL" in option names is weird in 2023 Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231003064352.2902298-2-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).