Skip to content

Add read_timeout #25

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

Merged
merged 2 commits into from
Apr 11, 2025
Merged

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 .

@TDannhauer TDannhauer changed the base branch from master to FRAMEWORK_6_0 April 10, 2025 21:03
Copy link

@TDannhauer TDannhauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for me.

@TDannhauer TDannhauer requested a review from ralflang April 10, 2025 21:06
@ralflang ralflang merged commit 8b972f9 into horde:FRAMEWORK_6_0 Apr 11, 2025
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.

3 participants