New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I receive socket error: EOF when trying to use IDLE #234
Comments
As far as I can see, you're not doing anything stupid :) It's hard to say but given the intermittent and infrequent nature of the problem I'm guessing that the cause is more likely to be a networking issue. In order to diagnose this further you could try adding If you're comfortable with tcpdump, it would also be useful to get a dump of the network traffic for the IMAP connection. This will let us know if the Yandex servers are dropping the connection. I'm pretty short on time at the moment but I can try and replicate if you aren't able to troubleshoot further. One side issue: selecting a folder is often an expensive operation (server side). You might want to move the |
Another thing: you might want to look inside |
Yandex mandates SSL, so I used sslsplit instead of tcpdump. Hope that's fine. Program output:
Sslstrip output:
Looks like the server is resending the greeting unexpectedly? Any reason why it should do that? |
Oh, sorry, of course the sslstrip output doesn't show the TCP packets, and you need those. I managed to get tcpdump working by using stunnel to handle SSL. It looks like you guessed right, the server is closing the connection while we're idling. I'm including the pcap in case it helps. snip2.zip |
Ha! I ended up creating a Yandex account and am running a test with tcpdump running right now :) You're right that I was interested in the TCP packets. There's no real need to get inside the SSL data - just the TCP level information is probably enough. ... and I just reproduced the EOF. I had added some printing of timestamps to your example and for me at least it looks like the connection was dropped almost exactly 10 mins after the IDLE was started. I'm guessing that Yandex is dropping inactive connections after 10 mins. If so, this mildly violates the IDLE spec as connections in IDLE are supposed to live for at least 29 mins. Unfortunately I screwed up my tcpdump filter so I've got the wrong packets. Looking at your capture the timing between the IDLE start and the connection being killed appears to be ~90s so maybe my hypothesis is wrong and there's something else happening. It does look like that Yandex is closing the connection though. |
I believe I've tried making the IDLE connections shorter, in the 2-5 minute range, and that didn't really help. My best guess right now is that IDLE connections eventually die for some reason on Yandex, but if you restart them often enough, you're less likely to encounter the hiccup. I'm running a test with a 5 minute idle time right now, I'll see what I can find. |
Update - connection died in the same way after about 45 minutes. I'm not convinced the IDLE connection length is a factor... |
You're right that the IDLE time doesn't appear to be a factor. I was misled by my first attempt which happened to land on almost exactly 10 mins. I've just seen another EOF after 6 minutes. I guess the right thing to do is handle these failures robustly in your program. Although Yandex seems to be dropping connections a little more than they should, network connections can fail at any time for for any number of reasons and our software has to be prepared for that. |
That's what I've been trying to do with the exception code that gets me a new connection before restarting the loop. Is there a better way to handle that?
True - but it doesn't make very much sense for Yandex to just kill a long running IMAP connection. I wonder if I should report this to them? |
We run IDLE connections on a wide variety of providers, most of them work well by reactivating the IDLE connection every 15 minutes. For ~5% of the accounts however, one of these two things happen:
The solution found is to keep track of the bad actors and fallback to polling for them. |
Using the latest version of imapclient, with the yandex.com IMAP server. Yandex email accounts are free if you want to test this.
My code:
It works most of the time but will randomly choke once or twice per hour with the aforementioned "socket error: EOF" (which I think is coming from imaplib). I suppose this could be a problem with the Yandex server, but that seems unlikely? Am I doing something stupid?
The text was updated successfully, but these errors were encountered: