You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If stream timeouts on some network that is blocking the connection, PHP function fgets(resource $stream, ?int $length = null): string|false returns false instead of empty string '' so the 'timed_out' metadata check will not be executed and you will end up with the error Expected response code "220" but got empty code.. AbstractStream.php#L77
$line = fgets($this->out);
if ('' === $line) {
$metas = stream_get_meta_data($this->out);
if ($metas['timed_out']) {
thrownewTransportException(sprintf('Connection to "%s" timed out.', $this->getReadConnectionDescription()));
}
if ($metas['eof']) {
thrownewTransportException(sprintf('Connection to "%s" has been closed unexpectedly.', $this->getReadConnectionDescription()));
}
}
How to reproduce
In my case, there is a blocked port 587 so when I try to connect to any XOauth2 SMTP servers it will wait for the amount of time set by the timeout setting and then throw Expected response code "220" but got empty code. instead of Connection to "SMTP" timed out..
Since the PHP documentation clearly states that fgets can return false I don't see the point in trying to reproduce it, stream metadata should be checked even if $line = false.
Possible Solution
stream metadata should be checked even if $line = false.
$line = fgets($this->out);
if ('' === $line || false === $line) {
$metas = stream_get_meta_data($this->out);
if ($metas['timed_out']) {
thrownewTransportException(sprintf('Connection to "%s" timed out.', $this->getReadConnectionDescription()));
}
if ($metas['eof']) {
thrownewTransportException(sprintf('Connection to "%s" has been closed unexpectedly.', $this->getReadConnectionDescription()));
}
}
…Sezil)
This PR was submitted for the 5.4 branch but it was merged into the 4.4 branch instead.
Discussion
----------
[Mailer] Stream timeout not detected fgets returns false
#48074 [Mailer] Stream timeout not detected due to checking only string result of function fgets
| Q | A
| ------------- | ---
| Branch? | 6.2 for features / 4.4, 5.4, 6.0 or 6.1 for bug fixes <!-- see below -->
| Bug fix? | yes/no
| New feature? | yes/no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | yes/no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License | MIT
| Doc PR | symfony/symfony-docs#... <!-- required for new features -->
<!--
Replace this notice by a short README for your feature/bugfix.
This will help reviewers and should be a good start for the documentation.
Additionally (see https://symfony.com/releases):
- Always add tests and ensure they pass.
- Bug fixes must be submitted against the lowest maintained branch where they apply
(lowest branches are regularly merged to upper ones so they get the fixes too).
- Features and deprecations must be submitted against the latest branch.
- For new features, provide some code snippets to help understand usage.
- Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry
- Never break backward compatibility (see https://symfony.com/bc).
-->
Commits
-------
486f2c5 [Mailer] Stream timeout not detected due to checking only string result of function fgets
Symfony version(s) affected
5.4
Description
If stream timeouts on some network that is blocking the connection, PHP function fgets(resource $stream, ?int $length = null): string|false returns
false
instead of empty string''
so the'timed_out'
metadata check will not be executed and you will end up with the errorExpected response code "220" but got empty code.
.AbstractStream.php#L77
How to reproduce
In my case, there is a blocked port 587 so when I try to connect to any XOauth2 SMTP servers it will wait for the amount of time set by the timeout setting and then throw
Expected response code "220" but got empty code.
instead ofConnection to "SMTP" timed out.
.Since the PHP documentation clearly states that
fgets
can returnfalse
I don't see the point in trying to reproduce it, stream metadata should be checked even if$line = false
.Possible Solution
stream metadata should be checked even if
$line = false
.Additional Context
EXCEPTION
Class: Symfony\Component\Mailer\Exception\TransportException
Message: Expected response code "220" but got empty code.
Code: 0
Stack trace:
The text was updated successfully, but these errors were encountered: