Skip to content
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

Add read_timeout #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bytestream
Copy link
Contributor

@bytestream bytestream commented Feb 6, 2023

If you download an email with a large attachment (30M, for example), and disconnect your local network interface mid way through https://github.com/bytestream/Imap_Client/blob/ac98de92168777fb8bf0bacf3129fc178523defe/lib/Horde/Imap/Client/Socket/Connection/Socket.php#L186 then Horde hangs indefinitely. feof hangs indefinitely when the stream is in blocking mode and the client disconnects - php/php-src#10495. Temporarily making it non-blocking, with a read timeout, resolves the issue.

Similarly _sendCmdChunk can loop indefinitely on a read/timeout error.

@what-the-diff
Copy link

what-the-diff bot commented Feb 6, 2023

  • Added read_timeout parameter to the constructor of Horde\Imap\Client.
  • Added SERVER_READTIMEOUT exception code and message in case of timeout error during reading from socket stream.
  • Changed _sendCmdChunk() method so that it can handle timeouts while waiting for server response (eof).
  • In Socket::read(), added handling of read timeout, which is thrown if no data received within specified period (default 120 seconds) or when eof reached before all literal bytes were sent by server side; also changed default value for 'timeout' option to 30 seconds instead of 0 - this means that we will wait forever until some data arrives on a socket stream unless explicitly set otherwise via options array passed into client's constructor; finally, made sure that blocking mode was restored after finishing with non-blocking reads from a socket stream as per PHP documentation recommendation: https://www.php-figures/streams#warning-about-nonblocking--whence---offset .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant