Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the IO-Pty-Easy CPAN distribution.

Report information
The Basics
Id: 95702
Status: open
Priority: 0/
Queue: IO-Pty-Easy

People
Owner: Nobody in particular
Requestors: ANDK [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.09
Fixed in: (no value)



Subject: Random test results
On my linux smoker I noticed 4 pass and 4 fails with the same perl v5.19.11. If it fails, it is always # Failed test 'write returns undef on timeout' # at t/read-write.t line 18. # got: '11' # expected: undef in t/read-write.t. So I watched the smoker testing in a loop and found that if I run for long enough I always get both a pass and a fail. HTH&&Thanks,
Additional datapoints: same observation for v5.18.2 on linux; whereas reliable PASSes on my freebsd10 with v5.18.2
From: ppisar [...] redhat.com
On 2014-5月-15 木 21:38:43, ANDK wrote: Show quoted text
> # Failed test 'write returns undef on timeout' > # at t/read-write.t line 18. > # got: '11' > # expected: undef > > in t/read-write.t. So I watched the smoker testing in a loop and found > that if I run for long enough I always get both a pass and a fail. >
I think there is a race between blocking the $pty write buffer by "$pty->write('a'x(1024*1024));" command and the tested "$pty->write("should fail", 0.1)" in the ALRM handler. For example the scheduler can halt before the "$pty->write('a'x(1024*1024));" command, so the SIGALRM arrives sooner that then buffer can be filled up.
From: ppisar [...] redhat.com
On 2016-3月-04 金 08:18:46, ppisar wrote: Show quoted text
> I think there is a race between blocking the $pty write buffer by > "$pty->write('a'x(1024*1024));" command and the tested "$pty-
> >write("should fail", 0.1)" in the ALRM handler.
> > For example the scheduler can halt before the "$pty-
> >write('a'x(1024*1024));" command, so the SIGALRM arrives sooner that
> then buffer can be filled up.
Attached fixes it by reworking the test. But I worry there is no POSIX interface that can guarantee once blocked buffer will remain blocked forever. I think the whole idea of the (original and the patched) test is flawed.
Subject: IO-Pty-Easy-0.09-Fix-a-race-in-t-read-write.t-test.patch
From 577a0eeb998f5bb120304f91b5a8a33bc8d3c6c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com> Date: Fri, 4 Mar 2016 15:04:48 +0100 Subject: [PATCH] Fix a race in t/read-write.t test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There was a race between filling a write buffer and testing a subsequent write would block. This patch fills the buffer first, and then it tests the blocking. CPAN RT#95702 Signed-off-by: Petr Písař <ppisar@redhat.com> --- t/read-write.t | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/t/read-write.t b/t/read-write.t index 21fe729..03c0bc0 100644 --- a/t/read-write.t +++ b/t/read-write.t @@ -12,17 +12,15 @@ like($pty->read, qr/testing/, "basic read/write testing"); is($pty->read(0.1), undef, "read returns undef on timeout"); $pty->kill; -$pty->spawn("$^X -e 'sleep(1) while 1'"); -eval { - local $SIG{ALRM} = sub { - is($pty->write("should fail", 0.1), undef, - "write returns undef on timeout"); - $SIG{ALRM} = 'DEFAULT'; - alarm 1; - }; - alarm 1; - $pty->write('a'x(1024*1024)); +ok($pty->spawn("$^X -e 'print qq{start\n}; sleep(1) while 1'"), + 'Program spawned'); +ok($pty->read, 'Program is ready'); +my $ret; +while (defined ($ret = $pty->write('a' x 1024, 1))) { + diag("Filling write buffer: +$ret"); }; +diag "Writte buffer filled"; +is($pty->write("should fail", 0.1), undef, "write returns undef on timeout"); $pty->kill; $pty->close; -- 2.5.0
From: ppisar [...] redhat.com
On 2016-3月-04 金 09:16:37, ppisar wrote: Show quoted text
> On 2016-3月-04 金 08:18:46, ppisar wrote:
> > I think there is a race between blocking the $pty write buffer by > > "$pty->write('a'x(1024*1024));" command and the tested "$pty-
> > > write("should fail", 0.1)" in the ALRM handler.
> > > > For example the scheduler can halt before the "$pty-
> > > write('a'x(1024*1024));" command, so the SIGALRM arrives sooner > > > that
> > then buffer can be filled up.
> > Attached fixes it by reworking the test. >
This version fixes a subtest because of a bug in the spawn() documentation, CPAN RT#113038.
Subject: IO-Pty-Easy-0.09-Fix-a-race-in-t-read-write.t-test.patch
From aad6946cd217f628c75d180af58f9ce38e637e22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com> Date: Fri, 4 Mar 2016 15:04:48 +0100 Subject: [PATCH] Fix a race in t/read-write.t test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There was a race between filling a write buffer and testing a subsequent write would block. This patch fills the buffer first, and then it tests the blocking. CPAN RT#95702 Signed-off-by: Petr Písař <ppisar@redhat.com> --- t/read-write.t | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/t/read-write.t b/t/read-write.t index 21fe729..5d63205 100644 --- a/t/read-write.t +++ b/t/read-write.t @@ -12,17 +12,14 @@ like($pty->read, qr/testing/, "basic read/write testing"); is($pty->read(0.1), undef, "read returns undef on timeout"); $pty->kill; -$pty->spawn("$^X -e 'sleep(1) while 1'"); -eval { - local $SIG{ALRM} = sub { - is($pty->write("should fail", 0.1), undef, - "write returns undef on timeout"); - $SIG{ALRM} = 'DEFAULT'; - alarm 1; - }; - alarm 1; - $pty->write('a'x(1024*1024)); +$pty->spawn("$^X -e 'print qq{start\n}; sleep(1) while 1'"); +ok($pty->read, 'Program is ready'); +my $ret; +while (defined ($ret = $pty->write('a' x 1024, 1))) { + diag("Filling write buffer: +$ret"); }; +diag "Writte buffer filled"; +is($pty->write("should fail", 0.1), undef, "write returns undef on timeout"); $pty->kill; $pty->close; -- 2.5.0