[PATCH] Re: fix hang because of infinite loop reading EOF
Nicolas Sebrecht
nicolas.s-dev at laposte.net
Thu Mar 3 18:01:56 GMT 2011
On Thu, Mar 03, 2011 at 09:04:02AM +0100, Sebastian Spaeth wrote:
> On Thu, 03 Mar 2011 10:46:33 +0800, Haojun Bao <baohaojun at gmail.com> wrote:
> > Offlineimap sometimes hangs when downloading gmail with large
> > attachment.
> >
> > This is because of several infinite loop when reading the socket while
> > the EOF has happened. It can be seen from 2 facts:
Thank you for the spot! Your analyse is interresting.
> I think your patch might be safe and should most probably be included
> (with some comment in the code explaining why we need that check and
> abort I guess). However, will that be enough? If we are in the state you
> describe the connection has basically been closed and the file
> descriptor is worthless, right?
>
> So it is ok to abort the read(), but it will not close the connection,
> and we will be trying to read from the same connection soon again. And
> subsequent read() attempts will also not be successful then, right?
>
> So what we should do in a case where we detect a broken connection is to
> properly kill off the connection and re-establish it.
>
> Or am I completely wrong here?
I think you're right. This is what the CLOSE_WAIT status seems to say,
at least. It would nice to know what is causing this CLOSE_WAIT status
in the first place.
Anyway, if a read() can't be done due to a closed socket, it would
probably be better to raise a dedicated error and not let the driver do
unexpected things with the data. We could then catch it and decide what
to do on such error from the socket manager.
--
Nicolas Sebrecht
More information about the OfflineIMAP-project
mailing list