Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > how to close a stalled file descriptor?

Reply
Thread Tools

how to close a stalled file descriptor?

 
 
Glenn
Guest
Posts: n/a
 
      10-29-2007
I'm having trouble closing a file descriptor on a stalled named pipe.
To unblock myself if the write takes too long because the pipe is full
and there is no reader on the other end of the pipe, I put in place
a signal handler. But if the signal handler is invoked and I regain
control, on any subsequent attempt to close the file descriptor,
it stalls again! How do I force the file descriptor to close so I
don't have an infinite buildup of file descriptors in my process,
if I want to continue operating? Even a simple "die" or "exit"
won't work because it tries to close the file descriptor and hangs!

 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      10-29-2007

Quoth Glenn <(E-Mail Removed)>:
> I'm having trouble closing a file descriptor on a stalled named pipe.
> To unblock myself if the write takes too long because the pipe is full
> and there is no reader on the other end of the pipe, I put in place
> a signal handler.


Which OS are you using? Under most Unices, a writing to a full pipe with
no readers will first send SIGPIPE, and if that is handled or ignored,
fail with EPIPE.

> But if the signal handler is invoked and I regain
> control, on any subsequent attempt to close the file descriptor,
> it stalls again!


When you say 'file descriptor' do you mean 'Perl file handle'? Which
perl version are you using? Are you using PerlIO? It's possible that you
are closing a Perl FH, which is attempting to flush its buffers and
handling the error badly. If this is the case, then you may be able to
ignore (and lose) the buffer by pushing a :unix layer before you close.

Ben

 
Reply With Quote
 
 
 
 
Glenn
Guest
Posts: n/a
 
      10-30-2007
On Oct 29, 3:03 pm, Ben Morrow <(E-Mail Removed)> wrote:
> Quoth Glenn <(E-Mail Removed)>:
>
> > I'm having trouble closing a file descriptor on a stalled named pipe.
> > To unblock myself if the write takes too long because the pipe is full
> > and there is no reader on the other end of the pipe, I put in place
> > a signal handler.

>
> Which OS are you using? Under most Unices, a writing to a full pipe with
> no readers will first send SIGPIPE, and if that is handled or ignored,
> fail with EPIPE.


I'm testing this on Red Hat Linux 4. But bear in mind that named
pipes
differ from anonymous pipes in one important aspect. A named pipe can
be written to before any reader has attached to the pipe. In that
case,
no SIGPIPE or EPIPE will arise. Those error conditions only arise if
an
attached reader closes the pipe. Without such a reader in the first
place,
there's no such feedback, and all I have is my own SIGALRM timeout to
tell
that the data is not being read.

> > But if the signal handler is invoked and I regain
> > control, on any subsequent attempt to close the file descriptor,
> > it stalls again!

>
> When you say 'file descriptor' do you mean 'Perl file handle'? Which
> perl version are you using? Are you using PerlIO? It's possible that you
> are closing a Perl FH, which is attempting to flush its buffers and
> handling the error badly. If this is the case, then you may be able to
> ignore (and lose) the buffer by pushing a :unix layer before you close.


Yes, I mean 'Perl file handle'. I'm running v5.8.8. I didn't know
about
PerlIO, so I'm not explicitly using it, but "perldoc open" says it's
now
the default IO system.

Yes, it seems like the Perl FH, in trying to flush its buffers, is
continuing the write operation (a large write to a small pipe) and
therefore hanging (there's no error condition to be handled).

I hadn't known about these i/o disciplines. Opening the pipe in the
first place with an explicit :unix discipline (and thereby not
stacking
whatever other buffering would normally be induced on the i/o stream)
has cured the problem. Thanks!!


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How to close a TCP socket? (TCPSocket#close doesn't close it) IƱaki Baz Castillo Ruby 7 01-12-2010 01:32 PM
Stalled ticket in Python bug tracker Steven D'Aprano Python 6 01-24-2009 08:39 AM
After running for four days, Python program stalled John Nagle Python 2 12-12-2007 09:26 PM
PC boot-up stalled Ken Doughty Computer Support 7 02-11-2004 07:33 PM



Advertisments