Skip to content

Commit f6826fc

Browse files
committed
Tests: handling of EWOULDBLOCK from sysread() with IO::Socket::SSL.
With IO::Socket::SSL, when select() reports that the socket is readable, reading from it might still fail with EWOULDBLOCK, since no application data is available in the socket. In particular, this might happen with TLSv1.3 when a session ticket is received after the handshake. Fix is to explicitly check for EWOULDBLOCK errors.
1 parent cd57719 commit f6826fc

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

lib/Test/Nginx/IMAP.pm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ sub getline {
6868
while (IO::Select->new($socket)->can_read(8)) {
6969
$socket->blocking(0);
7070
my $n = $socket->sysread(my $buf, 1024);
71+
my $again = !defined $n && $!{EWOULDBLOCK};
7172
$socket->blocking(1);
73+
next if $again;
7274
last unless $n;
7375

7476
$self->{_read_buffer} .= $buf;

lib/Test/Nginx/POP3.pm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ sub getline {
6868
while (IO::Select->new($socket)->can_read(8)) {
6969
$socket->blocking(0);
7070
my $n = $socket->sysread(my $buf, 1024);
71+
my $again = !defined $n && $!{EWOULDBLOCK};
7172
$socket->blocking(1);
73+
next if $again;
7274
last unless $n;
7375

7476
$self->{_read_buffer} .= $buf;

lib/Test/Nginx/SMTP.pm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ sub getline {
6868
while (IO::Select->new($socket)->can_read(8)) {
6969
$socket->blocking(0);
7070
my $n = $socket->sysread(my $buf, 1024);
71+
my $again = !defined $n && $!{EWOULDBLOCK};
7172
$socket->blocking(1);
73+
next if $again;
7274
last unless $n;
7375

7476
$self->{_read_buffer} .= $buf;

lib/Test/Nginx/Stream.pm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,10 @@ sub read {
8484
$s = $self->{_socket};
8585

8686
$s->blocking(0);
87-
if (IO::Select->new($s)->can_read($extra{read_timeout} || 8)) {
88-
$s->sysread($buf, 1024);
87+
while (IO::Select->new($s)->can_read($extra{read_timeout} || 8)) {
88+
my $n = $s->sysread($buf, 1024);
89+
next if !defined $n && $!{EWOULDBLOCK};
90+
last;
8991
}
9092

9193
log_in($buf);

0 commit comments

Comments
 (0)