mwrap (Perl version) user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <mwrap-perl@80x24.org>
To: mwrap-perl@80x24.org
Subject: [PATCH 3/3] rproxy: more thorough connectivity check
Date: Fri, 16 Dec 2022 22:57:54 +0000	[thread overview]
Message-ID: <20221216225754.96103-4-mwrap-perl@80x24.org> (raw)
In-Reply-To: <20221216225754.96103-1-mwrap-perl@80x24.org>

Sometimes, stale sockets can stick around and the PID gets
recycled by a different process, so ensure we can actually
connect to it before listing it.
---
 lib/Devel/Mwrap/Rproxy.pm | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/lib/Devel/Mwrap/Rproxy.pm b/lib/Devel/Mwrap/Rproxy.pm
index 76b7d7f..6db72e6 100644
--- a/lib/Devel/Mwrap/Rproxy.pm
+++ b/lib/Devel/Mwrap/Rproxy.pm
@@ -41,11 +41,15 @@ sub list {
 	open(my $fh, '+>', \(my $str)) or die "open: $!";
 	print $fh '<html><head><title>', $t, '</title></head><body><pre>', $t,
 		"\n\n";
-	opendir(my $dh, $self->{socket_dir}) or return r(500, "socket_dir: $!");
-	my @pids = grep(/\A[0-9]+\.sock\z/, readdir($dh));
-	for (@pids) {
+	my $dir = $self->{socket_dir};
+	opendir(my $dh, $dir) or return r(500, "socket_dir: $!");
+	my @socks = grep(/\A[0-9]+\.sock\z/, readdir($dh));
+	my %o = (Type => SOCK_STREAM, Peer => undef);
+	for (@socks) {
+		$o{Peer} = "$dir/$_";
 		substr($_, -5, 5, ''); # chop off .sock
 		my $cmd = $valid_pid->($_) // next;
+		my $c = IO::Socket::UNIX->new(%o) // next;
 		print $fh qq(<a\nhref="./$_/">$_</a>/);
 		$_ .= '/each/2000';
 		say $fh qq(<a\nhref="./), $_, qq(">each/2000</a>\t), $cmd;

      parent reply	other threads:[~2022-12-16 22:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-16 22:57 [PATCH 0/3] more rproxy+httpd tweaks Eric Wong
2022-12-16 22:57 ` [PATCH 1/3] rproxy: manpage updates Eric Wong
2022-12-16 22:57 ` [PATCH 2/3] httpd: more thorough unlinking of stale sockets Eric Wong
2022-12-16 22:57 ` Eric Wong [this message]

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

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

  git send-email \
    --in-reply-to=20221216225754.96103-4-mwrap-perl@80x24.org \
    --to=mwrap-perl@80x24.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mwrap-perl.git

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).