Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$! not set to ECONNRESET in IO::Socket if TCP connection is reset #13897

Closed
p5pRT opened this issue Jun 2, 2014 · 10 comments
Closed

$! not set to ECONNRESET in IO::Socket if TCP connection is reset #13897

p5pRT opened this issue Jun 2, 2014 · 10 comments

Comments

@p5pRT
Copy link

p5pRT commented Jun 2, 2014

Migrated from rt.perl.org#122018 (status was 'rejected')

Searchable as RT122018$

@p5pRT
Copy link
Author

p5pRT commented Jun 2, 2014

From jesper.j.persson@gmail.com

see http​://www.mail-archive.com/libwww@​perl.org/msg07072.html

Best Regards
Jesper Persson

Summary of my perl5 (revision 5 version 18 subversion 2) configuration​:

  Platform​:
  osname=MSWin32, osvers=6.2, archname=MSWin32-x64-multi-thread
  uname='Win32 strawberry-perl 5.18.2.2 #1 Tue Apr 15 14​:36​:23 2014 x64'
  config_args='undef'
  hint=recommended, useposix=true, d_sigaction=undef
  useithreads=define, usemultiplicity=define
  useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
  use64bitint=define, use64bitall=undef, uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='gcc', ccflags =' -s -O2 -DWIN32 -DWIN64 -DCONSERVATIVE
-DPERL_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS
-DUSE_PERLIO -fno-
strict-aliasing -mms-bitfields',
  optimize='-s -O2',
  cppflags='-DWIN32'
  ccversion='', gccversion='4.7.3', gccosandvers=''
  intsize=4, longsize=4, ptrsize=8, doublesize=8, byteorder=12345678
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
  ivtype='long long', ivsize=8, nvtype='double', nvsize=8, Off_t='long
long', lseeksize=8
  alignbytes=8, prototype=define
  Linker and Libraries​:
  ld='g++', ldflags ='-s -L"C​:\strawberry\perl\lib\CORE"
-L"C​:\strawberry\c\lib"'
  libpth=C​:\strawberry\c\lib C​:\strawberry\c\x86_64-w64-mingw32\lib
C​:\strawberry\c\lib\gcc\x86_64-w64-mingw32\4.7.3
  libs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32
-ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr
-lwinmm
-lversion -lodbc32 -lodbccp32 -lcomctl32
  perllibs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32
-ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lw
inmm -lversion -lodbc32 -lodbccp32 -lcomctl32
  libc=, so=dll, useshrplib=true, libperl=libperl518.a
  gnulibc_version=''
  Dynamic Linking​:
  dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
  cccdlflags=' ', lddlflags='-mdll -s -L"C​:\strawberry\perl\lib\CORE"
-L"C​:\strawberry\c\lib"'

Characteristics of this binary (from libperl)​:
  Compile-time options​: HAS_TIMES HAVE_INTERP_INTERN MULTIPLICITY
  PERLIO_LAYERS PERL_DONT_CREATE_GVSV
  PERL_HASH_FUNC_ONE_AT_A_TIME_HARD
  PERL_IMPLICIT_CONTEXT PERL_IMPLICIT_SYS
  PERL_MALLOC_WRAP PERL_PRESERVE_IVUV
PERL_SAWAMPERSAND
  USE_64_BIT_INT USE_ITHREADS USE_LARGE_FILES
  USE_LOCALE USE_LOCALE_COLLATE USE_LOCALE_CTYPE
  USE_LOCALE_NUMERIC USE_PERLIO USE_PERL_ATOF
  Built under MSWin32
  Compiled at Apr 15 2014 14​:45​:10
  @​INC​:
  C​:/strawberry/perl/site/lib
  C​:/strawberry/perl/vendor/lib
  C​:/strawberry/perl/lib

@p5pRT
Copy link
Author

p5pRT commented Jun 2, 2014

From @jkeenan

On Mon Jun 02 09​:03​:36 2014, jesper.j.persson@​gmail.com wrote​:

see http​://www.mail-archive.com/libwww@​perl.org/msg07072.html

Best Regards
Jesper Persson

Jesper, we'll have to quote that message directly if this bug report is going to get the attention you would like for it.

The following is a code excerpt and then a response -- and implicit wishlist item -- from Steffen Ullrich.

  READ​:
  {
  die "read timeout" unless $self->can_read;
  my $n = $self->sysread($_, 1024, length);
  unless (defined $n) {
  redo READ if $!{EINTR} || $!{EAGAIN};

The server makes a connection reset if you try to access https://www.butler.edu/boa/default.aspx. On unix this will set $! to ECONNRESET, and for unknown reason this will not set $! on Windows with Strawberry perl5.18.2 , but only returns "SSL read error" from the SSL layer.

Thus $! will stay at EINTR from the previous error and it will loop forever.

IO​::Socket​::SSL 1.992 (just released) works around this problem by resetting $! before doing I/O. This way $! will no longer stay at $!, but will be undef and thus the loop will exit, albeit with no specific error. The real fix would be of course to set $! to ECONNRESET in the underlying IO​::Socket layer if the TCP connection was reset.

@p5pRT
Copy link
Author

p5pRT commented Jun 2, 2014

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Jun 3, 2014

From @Leont

On Mon, Jun 2, 2014 at 10​:52 PM, James E Keenan via RT <
perlbug-followup@​perl.org> wrote​:

The server makes a connection reset if you try to access
https://www.butler.edu/boa/default.aspx. On unix this will set $! to
ECONNRESET, and for unknown reason this will not set $! on Windows with
Strawberry perl5.18.2 , but only returns "SSL read error" from the SSL
layer.

Thus $! will stay at EINTR from the previous error and it will loop
forever.

IO​::Socket​::SSL 1.992 (just released) works around this problem by
resetting $! before doing I/O. This way $! will no longer stay at $!, but
will be undef and thus the loop will exit, albeit with no specific error.
The real fix would be of course to set $! to ECONNRESET in the underlying
IO​::Socket layer if the TCP connection was reset.

This sounds like a bug in IO​::Socket​::SSL to me, not a bug in IO​::Socket. I
agree the "fix" in 1.992 is not a fix at all though.

Leon

@p5pRT
Copy link
Author

p5pRT commented Jun 5, 2014

From sullr@cpan.org

On 06/03/2014 02​:49 AM, Leon Timmermans wrote​:> On Mon, Jun 2, 2014 at 10​:52 PM,
James E Keenan via RT

<perlbug-followup@​perl.org <mailto​:perlbug-followup@​perl.org>> wrote​:

The server makes a connection reset if you try to access
https://www.butler.edu/boa/default.aspx. On unix this will set $\! to
ECONNRESET\, and for unknown reason this will not set $\! on Windows with
Strawberry perl5\.18\.2 \, but only returns "SSL read error" from the SSL layer\.


Thus $\! will stay at EINTR from the previous error and it will loop forever\.

IO&#8203;::Socket&#8203;::SSL 1\.992 \(just released\) works around this problem by resetting
$\! before doing I/O\. This way $\! will no longer stay at $\!\, but will be
undef and thus the loop will exit\, albeit with no specific error\. The real
fix would be of course to set $\! to ECONNRESET in the underlying IO&#8203;::Socket
layer if the TCP connection was reset\.

This sounds like a bug in IO​::Socket​::SSL to me, not a bug in IO​::Socket. I
agree the "fix" in 1.992 is not a fix at all though.

I doubt that it is a problem of IO​::Socket. I can successfully get ECONNRESET if
I use IO​::Socket​::INET only.

But once I add IO​::Socket​::SSL I get a problem, because Net​::SSLeay​::SSL_read
(called from IO​::Socket​::SSL sysread etc) returns undef, sets the error code to
-1 and the SSL error is ERROR_SYSCALL. According to the documentation of
SSL_get_error there must either by errors retrievable with ERRO_get_error (there
are none) or we must look at system errors, e.g errno in C or $! in Perl.

But, $! is undef on Windows and ECONNRESET on Linux, so somewhere it fails to
propagate errno from OpenSSL (where the actual reads on the file descriptor are
done) back to the Perl program.

According to some old posts I've found (from 2008, and they talk about problems
with Net​::SSLeay) this is a known problem, if there are different compilers
involved, e.g. if one compiler was used to built Perl and another to built the
OpenSSL library.
But this is Strawberry Perl which ships with Net​::SSLeay and IO​::Socket​::SSL
built in, so I would guess they've build everything together with the same
compiler.

I can also reproduce the problem with Strawberry 5.18.1 installed on the same
machine, so either the problem is not specific with 5.18.2 or they share the
same OpenSSL DLL or so when installed on the same machine and thus have the same
problem.

Another possibility is, that propagating a socket error must be done differently
on Windows and UNIX, but i have no experiences with this.

Steffen

@p5pRT
Copy link
Author

p5pRT commented Jun 6, 2014

From @Leont

On Thu, Jun 5, 2014 at 10​:15 PM, Steffen Ullrich <sullr@​cpan.org> wrote​:

On 06/03/2014 02​:49 AM, Leon Timmermans wrote​:> On Mon, Jun 2, 2014 at
10​:52 PM, James E Keenan via RT

<perlbug-followup@​perl.org <mailto​:perlbug-followup@​perl.org>> wrote​:

The server makes a connection reset if you try to access
https://www.butler.edu/boa/default.aspx. On unix this will set $\! to
ECONNRESET\, and for unknown reason this will not set $\! on Windows

with

Strawberry perl5\.18\.2 \, but only returns "SSL read error" from the

SSL layer.

Thus $\! will stay at EINTR from the previous error and it will loop

forever.

IO&#8203;::Socket&#8203;::SSL 1\.992 \(just released\) works around this problem by

resetting

$\! before doing I/O\. This way $\! will no longer stay at $\!\, but will

be

undef and thus the loop will exit\, albeit with no specific error\.

The real

fix would be of course to set $\! to ECONNRESET in the underlying

IO​::Socket

layer if the TCP connection was reset\.

This sounds like a bug in IO​::Socket​::SSL to me, not a bug in
IO​::Socket. I
agree the "fix" in 1.992 is not a fix at all though.

I doubt that it is a problem of IO​::Socket. I can successfully get
ECONNRESET if I use IO​::Socket​::INET only.

But once I add IO​::Socket​::SSL I get a problem, because
Net​::SSLeay​::SSL_read (called from IO​::Socket​::SSL sysread etc) returns
undef, sets the error code to -1 and the SSL error is ERROR_SYSCALL.
According to the documentation of SSL_get_error there must either by errors
retrievable with ERRO_get_error (there are none) or we must look at system
errors, e.g errno in C or $! in Perl.

But, $! is undef on Windows and ECONNRESET on Linux, so somewhere it fails
to propagate errno from OpenSSL (where the actual reads on the file
descriptor are done) back to the Perl program.

According to some old posts I've found (from 2008, and they talk about
problems with Net​::SSLeay) this is a known problem, if there are different
compilers involved, e.g. if one compiler was used to built Perl and another
to built the OpenSSL library.
But this is Strawberry Perl which ships with Net​::SSLeay and
IO​::Socket​::SSL built in, so I would guess they've build everything
together with the same compiler.

I can also reproduce the problem with Strawberry 5.18.1 installed on the
same machine, so either the problem is not specific with 5.18.2 or they
share the same OpenSSL DLL or so when installed on the same machine and
thus have the same problem.

Another possibility is, that propagating a socket error must be done
differently on Windows and UNIX, but i have no experiences with this.

IO​::Socket​::SSL is not a core module, so I think this ticket should be
closed as "wrong bug tracker". You want it's cpan.org RT queue (
https://rt.cpan.org/Dist/Display.html?Queue=IO-Socket-SSL). Also, $^E might
give you some more information on what's going on.

Leon

@p5pRT
Copy link
Author

p5pRT commented Jun 6, 2014

From @andk

Leon Timmermans <fawaka@​gmail.com> writes​:

IO​::Socket​::SSL is not a core module, so I think this ticket should be closed
as "wrong bug tracker". You want it's cpan.org RT queue (https://rt.cpan.org/
Dist/Display.html?Queue=IO-Socket-SSL). Also, $^E might give you some more
information on what's going on.

Leon, please scroll up this thread to "The real fix would be"

--
andreas

@p5pRT
Copy link
Author

p5pRT commented Jun 6, 2014

From @andk

Andreas Koenig <andreas.koenig.7os6VVqR@​franz.ak.mind.de> writes​:

Leon, please scroll up this thread to "The real fix would be"

Oops, sorry, ignore me. Apparently you did. I'll get some coffeine...

--
andreas

@p5pRT
Copy link
Author

p5pRT commented Jul 23, 2014

From @tonycoz

On Thu Jun 05 17​:43​:55 2014, LeonT wrote​:

IO​::Socket​::SSL is not a core module, so I think this ticket should be
closed as "wrong bug tracker". You want it's cpan.org RT queue (
https://rt.cpan.org/Dist/Display.html?Queue=IO-Socket-SSL). Also, $^E
might
give you some more information on what's going on.

I agree, this doesn't belong on rt.perl.org.

Marking rejected.

Tony

@p5pRT p5pRT closed this as completed Jul 23, 2014
@p5pRT
Copy link
Author

p5pRT commented Jul 23, 2014

@tonycoz - Status changed from 'open' to 'rejected'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant