Skip Menu |

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

Report information
The Basics
Id: 61233
Status: resolved
Priority: 0/
Queue: IO-Lambda

People
Owner: Nobody in particular
Requestors: njh [...] bandsman.co.uk
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 1.20
Fixed in: (no value)



Subject: getsockopt() on closed socket
I have just seen this error. Can you help? getsockopt() on closed socket GEN5843 at /usr/local/share/perl/5.10.1/IO/Lambda/HTTP.pm line 322 (#2) (W closed) You tried to get a socket option on a closed socket. Did you forget to check the return value of your socket() call? See perlfunc/getsockopt. [Fri Sep 10 00:28:13 2010] search.cgi: getsockopt() on closed socket GEN5843 at /usr/local/share/perl/5.10.1/IO/Lambda/HTTP.pm line 322. Use of uninitialized value in unpack at /usr/local/share/perl/5.10.1/IO/Lambda/HTTP.pm line 322 (#1) It is a large script which takes hours to run, so please don't ask me to produce a short program which easily reproduces this for you - I can't do that.
Strange, HTTP.pm doesn't actively close sockets, it does delete $self->{socket} so it gets closed automatically. Also, on a general level, if a closed socket gets in an active listener (readable, writable) IO::Lambda would explode much earlier (Loop/Select.pm:97). I'm thinking aloud here. Could that be that the socket gets closed by other code? You can try to redefine CORE::close() to track down where the socket gets destroyed, and match it with socket() where it is created. One socket can be shared between several instances, but should never in parallel, and even then refcount wouldn't allow a socket to be closed. I can't think of anything particular here, and would be curious to know how did a closed socket manage to get away from a die() in select() OTOH, the problem here is only warning and is fairly innocent - getsockopt() catches that the socket is problematic, and doesn't deposit it back to the cache. It doesn't expect it to be closed, and reasonably so, but then, if I can put an extra line for such a test, then the problem is solved. Gotta investigate how to check if a socket is alive.
From: njh [...] bandsman.co.uk
I'm certainly willing to try to help by redefining CORE::close(), but I'm out of my depth there, so I'd want to know how to do that. I should add that this is the first time I've ever seen it and it could be a one off caused by a difficult to find race condition. It is more serious than you think, but that's my fault - I didn't include the bottom part of the message, sorry. Here is the end of the report, and you can see it dies. ... [Fri Sep 10 00:28:13 2010] search.cgi: getsockopt() on closed socket GEN5831 at /usr/local/share/perl/5.10.1/IO/Lambda/HTTP.pm line 294. Use of uninitialized value in unpack at /usr/local/share/perl/5.10.1/IO/Lambda/HTTP.pm line 294 (#1) [Fri Sep 10 00:28:13 2010] search.cgi: Use of uninitialized value in unpack at /usr/local/share/perl/5.10.1/IO/Lambda/HTTP.pm line 294. Error:162 of /usr/local/share/perl/5.10.1/IO/Lambda/Loop/Select.pm: Invalid filehandle
Aha, so it does die in select, which is something already. You override close() with this: use Carp; BEGIN { *CORE::GLOBAL::close = sub { Carp::cluck("fh ", fileno($_[0]), " is closed"); CORE::close($_[0]); }; }; and let's see who's guilty.
From: njh [...] bandsman.co.uk
I tried it and no crash (as I suspected). My hunch is still that it's a race condition somewhere.
Срд Сен 15 04:52:54 2010, njh@bandsman.co.uk писал: Show quoted text
> I tried it and no crash (as I suspected). My hunch is still that it's a > race condition somewhere. >
Mine too. I'm ok that the bug stays open, and if you manage to find extra evidence I'll definitely help.
From: njh [...] bandsman.co.uk
I've finally got around to adding your code to override close() (sorry for the delay). However, my script no longer compiles: Subroutine main::confess redefined at /usr/share/perl5/Exporter.pm line 67. at ./search.cgi line 30 Subroutine main::croak redefined at /usr/share/perl5/Exporter.pm line 67. at ./search.cgi line 30 Subroutine main::carp redefined at /usr/share/perl5/Exporter.pm line 67. at ./search.cgi line 30 Bareword "URL" not allowed while "strict subs" in use at ./search.cgi line 1214. Bareword "PDFFILE" not allowed while "strict subs" in use at ./search.cgi line 1532. Bareword "PDFFILE" not allowed while "strict subs" in use at ./search.cgi line 1551. Bareword "GIFFILE" not allowed while "strict subs" in use at ./search.cgi line 1563. Bareword "GIFFILE" not allowed while "strict subs" in use at ./search.cgi line 1582. Bareword "DOCFILE" not allowed while "strict subs" in use at ./search.cgi line 1592. Bareword "DOCFILE" not allowed while "strict subs" in use at ./search.cgi line 1611. Bareword "MP3FILE" not allowed while "strict subs" in use at ./search.cgi line 1621. Bareword "MIDIFILE" not allowed while "strict subs" in use at ./search.cgi line 1656. ...
Look like "use Carp" in my code is guilty here - try "require Carp" inside BEGIN {}.
From: njh [...] bandsman.co.uk
On Tue Sep 28 01:23:02 2010, KARASIK wrote: Show quoted text
> Look like "use Carp" in my code is guilty here - try "require Carp" > inside BEGIN {}.
That fixes the first 3 errors, but the other ones, complaining about bareword not allowed, remain. All of those co-incide with calls to close routines, e.g.: close(URL);
Well, hm... either remove Carp altogether, but you'll need to traverse the stack yourself with caller(), or IIUC the script doesn't have "use strict", which cannot be a good idea nowadays :)
From: njh [...] bandsman.co.uk
On Wed Oct 06 18:00:03 2010, KARASIK wrote: Show quoted text
> Well, hm... either remove Carp altogether, but you'll need to traverse > the stack yourself with caller(), or IIUC the script doesn't have "use > strict", which cannot be a good idea nowadays :)
I'm not sure how to traverse the stack. I also don't know what IIUC means, so I removed 'use strict' from my script, but it still fails even though I have removed it: [Thu Oct 7 09:29:27 2010] search.cgi: [Thu Oct 7 09:29:27 2010] search.cgi: Bareword "FH" not allowed while "strict subs" in use at /usr/local/lib/perl5/DBI.pm line 2093.
Sorry, IIUC is "if I understand corerctly". I might be wrong here, but it looks like there are other problem in the script. Does the compilation fail after you added the BEGIN block? Possibly, you could send me a (stripped down) script so I could take a look at it? Looks mysterious - a fail in DBI.pm, well, something is wrong there.
From: njh [...] bandsman.co.uk
I will send you the script directly, rather than on this public forum.