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

Errno error in IO::Socket::INET #4052

Closed
p5pRT opened this issue May 31, 2001 · 3 comments
Closed

Errno error in IO::Socket::INET #4052

p5pRT opened this issue May 31, 2001 · 3 comments

Comments

@p5pRT
Copy link

p5pRT commented May 31, 2001

Migrated from rt.perl.org#7067 (status was 'resolved')

Searchable as RT7067$

@p5pRT
Copy link
Author

p5pRT commented May 31, 2001

From dfaraldo@nocpulse.com

[Note​: We were using the RedHat Perl distribution (perl-5.00503-10)
with IO​::Socket v1.603 on Linux, but it is apparently incompatible
with some kernels (both 2.2.14-5.0.14 and 2.2.14-5.0smp) because they
restart the connect(2) system call after being interrupted by a SIGALRM,
screwing up connect timeouts. That's why we're now trying to use v1.25
(from the Perl 5.6 distribution) with Perl 5.00503.]

IO​::Socket v1.25 doesn't return an error message under certain
circumstances (e.g. when the connection times out). For example,
the script​:

  #!/usr/bin/perl

  my $addr = "192.168.2.2"; # or any non-reachable address
  my $port = 5010;

  use IO​::Socket;

  my $sock = IO​::Socket​::INET->new(PeerAddr=>$addr,
  PeerPort=>$port,
  Proto=>'tcp',
  Timeout => 3);

  print "Connect failed​: $@​\n" unless ($sock);

produces​:

  Connect failed​: IO​::Socket​::INET​:

Digging into the code (IO​::Socket​::INET line 169), I see​:

  return _error($sock,"$!")
  unless @​raddr;

(i.e. set $@​ to "IO​::Socket​::INET​: $!" and return undef). However,
in the case of a failed IO​::Socket​::connect() call (i.e. bad address,
failed connect(2), or timeout), the connect call dies via 'croak' in
an eval, so $@​ (not $!) contains the error message.

I changed the line to

  return _error($sock, $! ? "$!" : $@​)
  unless @​raddr;

, which seems to work.

Perl Info


Site configuration information for perl 5.00503:

Configured by root at Wed Feb  2 15:34:50 EST 2000.

Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration:
  Platform:
    osname=linux, osvers=2.2.5-22smp, archname=i386-linux
    uname='linux porky.devel.redhat.com 2.2.5-22smp #1 smp wed jun 2 09:11:51 edt 1999 i686 unknown '
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef useperlio=undef d_sfio=undef
  Compiler:
    cc='cc', optimize='-O2 -m486 -fno-strength-reduce', gccversion=egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
    cppflags='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    ccflags ='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    stdchar='char', d_stdstdio=undef, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -ldl -lm -lc -lposix -lcrypt
    libc=, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    


@INC for perl 5.00503:
    /usr/lib/perl5/5.00503/i386-linux
    /usr/lib/perl5/5.00503
    /usr/lib/perl5/site_perl/5.005/i386-linux
    /usr/lib/perl5/site_perl/5.005
    .


Environment for perl 5.00503:
    HOME=/home/dfaraldo
    LANG=en_US
    LANGUAGE (unset)
    LD_LIBRARY_PATH=/usr/ucblib:/home/dfaraldo/lib:/usr/ucblib:/home/dfaraldo/lib:/usr/ucblib:/home/dfaraldo/lib:/usr/ucblib:/home/dfaraldo/lib
    LOGDIR (unset)
    PATH=/home/dfaraldo/bin/Linux-2.2.14-5.0.14:/home/dfaraldo/bin:/usr/local/bin:/usr/X11R6/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/bin/X11:/etc:/usr/etc:/home/oracle/OraHome1/bin
    PERL_BADLANG (unset)
    SHELL=/bin/tcsh

@p5pRT
Copy link
Author

p5pRT commented Jul 16, 2005

From @schwern

[dfaraldo@​nocpulse.com - Thu May 31 05​:01​:54 2001]​:

#!/usr/bin/perl

my $addr = "192.168.2.2"; # or any non-reachable address
my $port = 5010;

use IO​::Socket;

my $sock = IO​::Socket​::INET->new(PeerAddr=>$addr,
PeerPort=>$port,
Proto=>'tcp',
Timeout => 3);

print "Connect failed​: $@​\n" unless ($sock);

produces​:

Connect failed​: IO​::Socket​::INET​:

Digging into the code (IO​::Socket​::INET line 169), I see​:

    return \_error\($sock\,"$\!"\)
        unless @​raddr;

(i.e. set $@​ to "IO​::Socket​::INET​: $!" and return undef). However,
in the case of a failed IO​::Socket​::connect() call (i.e. bad address,
failed connect(2), or timeout), the connect call dies via 'croak' in
an eval, so $@​ (not $!) contains the error message.

I changed the line to

      return \_error\($sock\, $\! ? "$\!" : $@​\)
        unless @​raddr;

, which seems to work.

I am unable to reproduce this problem with 5.4.5, 5.5.3, 5.6.2 or 5.8.6
on OS X. I don't have a Linux machine handy with a 5.6.x to reproduce.
So I can't confirm that the bug is fixed, but there does seem to be
code in IO​::Socket​::INET to take into account both $! and $@​ in each error.

Anyone care to confirm?

@p5pRT p5pRT closed this as completed Jul 26, 2008
@p5pRT
Copy link
Author

p5pRT commented Jul 26, 2008

p5p@spam.wizbit.be - Status changed from 'open' to 'resolved'

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