Skip Menu |

This queue is for tickets about the Mail-IMAPClient CPAN distribution.

Report information
The Basics
Id: 39776
Status: resolved
Priority: 0/
Queue: Mail-IMAPClient

People
Owner: Nobody in particular
Requestors: me [...] davidsansome.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Selecting on an SSL socket in Mail::IMAPClient
Date: Thu, 2 Oct 2008 17:25:38 +0100
To: bug-Mail-IMAPClient [...] rt.cpan.org
From: "David Sansome" <me [...] davidsansome.com>
Hi, I've discovered some strange behaviour in Mail::IMAPClient when using a IO::Socket::SSL. The problem only occurs when I connect to a Dovecot IMAP server - I was unable to reproduce with Courier. I'm using: Ubuntu 8.04 Perl 5.8.8 Mail::IMAPClient 3.10 from CPAN IO::Socket::SSL 1.02-1 from Ubuntu packages Dovecot 1.0.10 from Ubuntu packages The problem occurs when I try to download a message body from Dovecot over SSL. It hangs for 30 seconds and eventually gives me the message: ERROR: Tag 9: Timeout after 30 seconds waiting for data from server Oddly, downloading the same message from Courier over SSL works fine. I turned on debugging and looked at the differences. This is from Courier (which worked): Sending: 11 UID FETCH 1 BODY[] Sent 23 bytes LITERAL: received literal in line * 1 FETCH (UID 1 BODY[] of length 1082; attempting to retrieve from the 1109 bytes in: [snip]<END_OF_iBuffer> Read: [snip] Mail::IMAPClient reads the whole of the message in one go - including the "11 OK FETCH completed" message that comes after. However, from Dovecot I see this: Sending: 9 UID FETCH 1 BODY[] Sent 22 bytes LITERAL: received literal in line * 1 FETCH (UID 1 BODY[] of length 1082; attempting to retrieve from the 992 bytes in: [snip] Received ret=90 and buffer = [snip]<END> while processing LITERAL ERROR: Tag 9: Timeout after 30 seconds waiting for data from server Mail::IMAPClient only gets 992 bytes from the server (for whatever reason), and so waits for more to be available and reads it in IMAPClient.pm line 1404. It only reads ($expected_size - length $litstring) bytes - the number of bytes in the message that it hasn't got yet. It seems that the SSL socket decodes a larger chunk than this (perhaps all the data that is available on the socket) and stores it in an internal buffer. This means that the next time IMAPClient returns to its loop and does CORE::select to wait for more data (the "OK FETCH completed" message), the select times out because there is no more data actually waiting to be processed. Calling sysread on the socket at this point actually does read some data, so this suggests that IO::Socket::SSL's select behaviour is a bit broken. I've attached a patch that checks if the socket isa IO::Socket::SSL, and if so calls its pending() function to get the number of bytes that are really available for reading. This seems to fix the problem for me - although I admit it's a bit of a hack :) Thanks, David

Message body is not shown because sender requested not to inline it.

Subject: Re: [rt.cpan.org #39776] Selecting on an SSL socket in Mail::IMAPClient
Date: Mon, 6 Oct 2008 20:58:31 +0200
To: David Sansome via RT <bug-Mail-IMAPClient [...] rt.cpan.org>
From: Mark Overmeer <mark [...] overmeer.net>
* David Sansome via RT (bug-Mail-IMAPClient@rt.cpan.org) [081002 16:26]: Show quoted text
> Thu Oct 02 12:26:30 2008: Request 39776 was acted upon. > Transaction: Ticket created by me@davidsansome.com > Queue: Mail-IMAPClient > Subject: Selecting on an SSL socket in Mail::IMAPClient > > I've discovered some strange behaviour in Mail::IMAPClient when using > a IO::Socket::SSL. The problem only occurs when I connect to a > Dovecot IMAP server - I was unable to reproduce with Courier.
I had two other reports of people with comparible problems, but they were unable to fix it. Yes, you give a sound theory about what happens. Would you mind this little rewrite: (all pending logic on one line) if($timeout) { # SSL sockets seems to buffer data internally, so there # might be some data in the buffer from a previous sysread # even if select says there is none. my $pending = $socket->isa("IO::Socket::SSL") && $socket->pending; my $nfound = 0; unless($pending) { my $rvec = 0; vec($rvec, fileno($self->Socket), 1) = 1; $nfound = CORE::select($rvec, undef, $rvec, $timeout); } unless($pending || $nfound) -- Regards, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
Subject: Re: [rt.cpan.org #39776] Selecting on an SSL socket in Mail::IMAPClient
Date: Tue, 7 Oct 2008 11:32:58 +0100
To: bug-Mail-IMAPClient [...] rt.cpan.org
From: "David Sansome" <me [...] davidsansome.com>
2008/10/6 Mark Overmeer via RT <bug-Mail-IMAPClient@rt.cpan.org>: Show quoted text
> Would you mind this little rewrite: (all pending logic on one line)
Yep that looks better. Looking at the code again I noticed that select is used a second time on that socket a bit lower down. I haven't noticed this one breaking yet, but it might be a good idea to do the same thing here too. I've attached a new patch. David

Message body is not shown because sender requested not to inline it.

Subject: Re: [rt.cpan.org #39776] Selecting on an SSL socket in Mail::IMAPClient
Date: Wed, 8 Oct 2008 11:00:04 +0200
To: David Sansome via RT <bug-Mail-IMAPClient [...] rt.cpan.org>
From: Mark Overmeer <mark [...] overmeer.net>
* David Sansome via RT (bug-Mail-IMAPClient@rt.cpan.org) [081007 10:33]: Show quoted text
> Queue: Mail-IMAPClient > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=39776 > > > Looking at the code again I noticed that select is used a second time > on that socket a bit lower down. I haven't noticed this one breaking > yet, but it might be a good idea to do the same thing here too. > I've attached a new patch.
Released as v3.11 Let's see what the community thinks about it... -- Regards, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
got fixed in 3.11