# HG changeset patch # User Maxim Dounin # Date 1679356659 -10800 # Node ID 3629eda94c1b711cca69ab7d1aef0ab2fc4a65cb # Parent 5d3aee48ed8e531827148326bde7f1b29d0cbe92 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. diff --git a/lib/Test/Nginx/IMAP.pm b/lib/Test/Nginx/IMAP.pm --- a/lib/Test/Nginx/IMAP.pm +++ b/lib/Test/Nginx/IMAP.pm @@ -68,7 +68,9 @@ sub getline { while (IO::Select->new($socket)->can_read(8)) { $socket->blocking(0); my $n = $socket->sysread(my $buf, 1024); + my $again = !defined $n && $!{EWOULDBLOCK}; $socket->blocking(1); + next if $again; last unless $n; $self->{_read_buffer} .= $buf; diff --git a/lib/Test/Nginx/POP3.pm b/lib/Test/Nginx/POP3.pm --- a/lib/Test/Nginx/POP3.pm +++ b/lib/Test/Nginx/POP3.pm @@ -68,7 +68,9 @@ sub getline { while (IO::Select->new($socket)->can_read(8)) { $socket->blocking(0); my $n = $socket->sysread(my $buf, 1024); + my $again = !defined $n && $!{EWOULDBLOCK}; $socket->blocking(1); + next if $again; last unless $n; $self->{_read_buffer} .= $buf; diff --git a/lib/Test/Nginx/SMTP.pm b/lib/Test/Nginx/SMTP.pm --- a/lib/Test/Nginx/SMTP.pm +++ b/lib/Test/Nginx/SMTP.pm @@ -68,7 +68,9 @@ sub getline { while (IO::Select->new($socket)->can_read(8)) { $socket->blocking(0); my $n = $socket->sysread(my $buf, 1024); + my $again = !defined $n && $!{EWOULDBLOCK}; $socket->blocking(1); + next if $again; last unless $n; $self->{_read_buffer} .= $buf; diff --git a/lib/Test/Nginx/Stream.pm b/lib/Test/Nginx/Stream.pm --- a/lib/Test/Nginx/Stream.pm +++ b/lib/Test/Nginx/Stream.pm @@ -84,8 +84,10 @@ sub read { $s = $self->{_socket}; $s->blocking(0); - if (IO::Select->new($s)->can_read($extra{read_timeout} || 8)) { - $s->sysread($buf, 1024); + while (IO::Select->new($s)->can_read($extra{read_timeout} || 8)) { + my $n = $s->sysread($buf, 1024); + next if !defined $n && $!{EWOULDBLOCK}; + last; } log_in($buf);