Comment 12 for bug 824797

Revision history for this message
Martin Pool (mbp) wrote : Re: [Bug 824797] Re: bzr serve doesn't drop idle/dead connections

On 19 September 2011 09:57, Andrew Bennetts
<email address hidden> wrote:
>> So, I can understand the desire to pass the file descriptor to
>> 'errors'. But what do you actually *do* if it returns something there:
>>
>> rs, _, xs = select.select([fd], [], [fd], timeout)
>>
>> if xs:
>>   ????
>>
>> Do I:
>>
>> 1) Ignore xs, but assume that it makes it more likely that select()
>>    will raise an exception?
>
> I don't understand why you'd expect more exceptions to be raised in this
> case.

It doesn't make `select` more likely to raise an exception. However,
it does make it more likely to _return_ when an error has occurred,
rather than just continuing to block.

>> 2) Treat xs having a file descriptor as meaning the client has timed
>>    out, and thus we should just clean up and go home?
>
> I don't think that's a good assumption.

No, I think it only means "there's something for you to know about",
rather than telling you it's necessarily dead.

>> 3) Try to do something like read on the descriptor in order to figure
>>    out what is actually wrong with it?
>
> That's a reasonable approach.
>
> With either 1 or 3, the difference vs. not passing any fds to the 3rd
> arg is that there are fewer cases where select will hang until the
> timeout.  Precisely which cases those are varies by platform,
> unfortunately.

+1

Since you're only passing one fd in, the question of what to do with
xs is a bit moot. If select returns nothing (ie timeout) you do the
timeout case, otherwise the only thing you can do is read from the fd
and then you'll get data, an error, or eof.

You could log it if you get a xs, just in case.

> It is, as I mentioned in my original mail.  e.g. IIRC a failure of a
> connect(2) is signalled via exceptfds on Windows but not on Linux.

I think so too, and that is confirmed by
<http://msdn.microsoft.com/en-us/library/ms740141(v=VS.85).aspx>. I
thought there were other cases where exceptfds could matter, but I
can't find a citation. At any rate I agree with spiv that checking it
seems likely to do no harm and it might help.