Skip to content

Commit 7a4128f

Browse files
authored
Merge pull request #4156 from norio-nomura/test-port-forwarding.pl-print-failed-to-listen-tcp
hack/test-port-forwarding.pl: add reporting "failed to listen tcp"
2 parents 8944d8b + 62da801 commit 7a4128f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

hack/test-port-forwarding.pl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,11 @@
187187
open(my $log, "< $ha_log") or die "Can't read $ha_log: $!";
188188
seek($log, $ha_log_size, 0) or die "Can't seek $ha_log to $ha_log_size: $!";
189189
my %seen;
190+
my %failed_to_listen_tcp;
190191
while (<$log>) {
191192
$seen{$1}++ if /(Forwarding TCP from .*? to ((\d.*?|\[.*?\]):\d+|\/[^"]+))/;
192193
$seen{$1}++ if /(Not forwarding TCP .*?:\d+)/;
194+
$failed_to_listen_tcp{$2}=$1 if /(failed to listen tcp: listen tcp (.*?:\d+):[^"]+)/;
193195
}
194196
close $log or die;
195197

@@ -220,6 +222,24 @@
220222
print "😕 Unexpected log message: $_\n";
221223
}
222224

225+
if (%failed_to_listen_tcp) {
226+
foreach (keys %failed_to_listen_tcp) {
227+
print "⚠️ $failed_to_listen_tcp{$_}\n";
228+
}
229+
my @tcp_list = keys %failed_to_listen_tcp;
230+
if ($Config{osname} eq "darwin") {
231+
my @lsof_args = map { "-iTCP\@$_" } @tcp_list;
232+
print `lsof -P @lsof_args`;
233+
} elsif ($Config{osname} eq "linux") {
234+
my @lss_args = map { "src = $_" } @tcp_list;
235+
my $ss_expression = join(" or ", @lss_args);
236+
print `sudo ss -lnpt "$ss_expression"`;
237+
} elsif ($Config{osname} eq "cygwin") {
238+
my @awk_args = map { "-e'/$_/'" } @tcp_list;
239+
print `netstat -aon | awk -e'/^ +Proto/' @awk_args`;
240+
}
241+
}
242+
223243
# Cleanup remaining netcat instances (and port forwards)
224244
print $lima "sudo pkill -x nc";
225245

0 commit comments

Comments
 (0)