cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Asking for the reversion of the pselect() patch

From: Jamie Lokier <jamie_at_shareable.org>
Date: Mon, 12 Mar 2007 14:15:40 +0000

Bryan Henderson wrote:
> >As far as I know (and I have looked into it somewhat), the only
> >portable way to combine signals and select/poll, with no race hazard,
> >is to have the signal handler write to a pipe, and the pipe included
> >in the select/poll set.
>
> I assume the race hazard you're talking about is the possibility of
> missing the signal.

Yes. I have no interest personally in whether libcurl has this hazard
or not, but I'm just passing on what I know about the issue and
portable solutions to it.

> I originally proposed a pselect()-based patch that would have closed the
> window entirely. It's not portable, but again the idea was to improve,
> not to achieve perfection, so systems without pselect() would continue
> to have what they have today.

It's worth noting that pselect() doesn't work as advertised on a
number of systems, including many Linuxes.

> But then I found out I had read the code wrong and it would in fact
> have been a regression because pselect() has that file descriptor
> limitation that the existing code, which uses poll(), does not.

That's why ppoll() exists :-)

> So then I lowered my sights and proposed a patch that can miss signals
> in a brief window, but works with all file descriptors and on all systems
> that have poll(), even if they don't have pselect(). The patch mainly just
> removes the code to ignore EINTR. For those systems that do have pselect(),
> it also does a signal blocking and unblocking thing in order to shorten
> the window of missed signals.

If signals are being used, I recommend simply limiting the timeout
value to select() or poll() to a finite value, like a few seconds.

It could be explicitly enabled by a run-time flag to libcurl, or it
could be done all the time.

That's easy to implement, and basically reliable on all systems - the
race hazard (blocking forever) is effectively eliminated by it.

And it doesn't have the API complications that self-pipe has.

I think that would work well in combination with any patch to reduce
the window when signals may be missed prior to select().

-- Jamie
Received on 2007-03-12