Welcome! Log In Create A New Profile

Advanced

Re: [PATCH 1 of 1] Tests: unbreak reading new stderr data after eof

Sergey Kandaurov
May 29, 2023 09:32AM
> On 26 May 2023, at 20:46, Maxim Dounin <mdounin@mdounin.ru> wrote:
>
> Hello!
>
> On Fri, May 26, 2023 at 03:24:12PM +0400, Sergey Kandaurov wrote:
>
>> # HG changeset patch
>> # User Sergey Kandaurov <pluknet@nginx.com>
>> # Date 1685100180 -14400
>> # Fri May 26 15:23:00 2023 +0400
>> # Node ID dc3539be2a14a0cd0b8be9e1e9aae8c95b806828
>> # Parent 4dad7cf8ebe807f9230a82dde5fc02b5e12e390b
>> Tests: unbreak reading new stderr data after eof.
>>
>> Tests don't expect to stop reading redirected stderr when end of file is
>> reached, but rather to read new data being appended, similar to "tail -f".
>> The behaviour is first changed in Ubuntu 23.04 Perl 5.36, by applying the
>> upstream patch [1], and is expected for inclusion in the next Perl 5.38.
>> The fix is to set filehandle's position to the end of file to clear the
>> error state and allow to continue readline() further from that position.
>>
>> [1] https://github.com/Perl/perl5/commit/80c1f1e45e8e
>>
>> Updated mail_error_log.t and stream_error_log.t for consistency.
>>
>> diff --git a/error_log.t b/error_log.t
>> --- a/error_log.t
>> +++ b/error_log.t
>> @@ -183,7 +183,9 @@ sub lines {
>> my ($t, $file, $pattern) = @_;
>>
>> if ($file eq 'stderr') {
>> - return map { $_ =~ /\Q$pattern\E/ } (<$stderr>);
>> + my $value = map { $_ =~ /\Q$pattern\E/ } (<$stderr>);
>> + seek $stderr, 0, Fcntl::SEEK_END;
>> + return $value;
>> }
>>
>> my $path = $t->testdir() . '/' . $file;
>
> The SEEK_END here would introduce a race: if some data are added
> after reading, SEEK_END will silently skip it. While probably not
> important here, it might be a good idea to avoid introducing
> unneeded races when possible. In particular, SEEK_SET might be a
> better option (untested).

Sure, tnx for the point.
For the record, SEEK_SET appears to avoid races.

>
> Upcoming perldelta recommends $handle->clearerr() instead, which
> indeed seems to be a more explicit option (untested too).
>
> https://github.com/Perl/perl5/blob/8db19a86dfa8408a91845da20ea7063f7646a913/pod/perldelta.pod#readline-no-longer-clears-the-stream-error-and-eof-flags
>

As we don't need to change the position, clearerr() fits better.
Pushed the updated change.

--
Sergey Kandaurov
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH 0 of 1] Tests: unbreak reading new stderr data after eof ...

Sergey Kandaurov 294 May 26, 2023 07:30AM

[PATCH 1 of 1] Tests: unbreak reading new stderr data after eof

Sergey Kandaurov 76 May 26, 2023 07:30AM

Re: [PATCH 1 of 1] Tests: unbreak reading new stderr data after eof

Maxim Dounin 83 May 26, 2023 12:48PM

Re: [PATCH 1 of 1] Tests: unbreak reading new stderr data after eof

Sergey Kandaurov 97 May 29, 2023 09:32AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 174
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready