Skip to content
This repository has been archived by the owner on Nov 17, 2021. It is now read-only.

Error suppression causes important debug information to be lost #1201

Closed
shachibista opened this issue Jun 26, 2019 · 1 comment
Closed

Error suppression causes important debug information to be lost #1201

shachibista opened this issue Jun 26, 2019 · 1 comment

Comments

@shachibista
Copy link

shachibista commented Jun 26, 2019

Q A
Bug report? no
Feature request? no
RFC? no
How used? Standalone/Symfony/3party
Swiftmailer version 6.2.1
PHP version 7.1.30

Observed behaviour

Error suppression causes warnings from stream_socket_client to be hidden and errno is 0.

Expected behaviour

Warnings from stream_socket_client should not be hidden by default.

Example

When trying to connect to a mail server with ssl at port 465, with error suppression:

Fatal error: Uncaught Swift_TransportException: Connection could not be established with host mail.example.org [ #0] in /mailtest/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:269
Stack trace:
#0 /mailtest/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php(58): Swift_Transport_StreamBuffer->establishSocketConnection()
#1 /mailtest/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(143): Swift_Transport_StreamBuffer->initialize(Array)
#2 /mailtest/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mailer.php(65): Swift_Transport_AbstractSmtpTransport->start()
#3 /mailtest/test.php(19): Swift_Mailer->send(Object(Swift_Message))
#4 {main}
  thrown in /mailtest/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php on line 269

Without error suppression:

Warning: stream_socket_client(): Peer certificate CN=`mail.somewhere-else.net' did not match expected CN=`mail.exmaple.org' in /mailtest/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php on line 267

Warning: stream_socket_client(): Failed to enable crypto in /mailtest/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php on line 267

Warning: stream_socket_client(): unable to connect to ssl://mail.example.org:465 (Unknown error) in /mailtest/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php on line 267

Fatal error: Uncaught Swift_TransportException: Connection could not be established with host mail.example.org [ #0] in /mailtest/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:269
Stack trace:
#0 /mailtest/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php(58): Swift_Transport_StreamBuffer->establishSocketConnection()
#1 /mailtest/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(143): Swift_Transport_StreamBuffer->initialize(Array)
#2 /mailtest/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mailer.php(65): Swift_Transport_AbstractSmtpTransport->start()
#3 /mailtest/test.php(19): Swift_Mailer->send(Object(Swift_Message))
#4 {main}
  thrown in /mailtest/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php on line 269

Error is suppressed at line 267 in StreamBuffer.php:

$this->stream = @stream_socket_client($host.':'.$this->params['port'], $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $streamContext);
@fabpot
Copy link
Member

fabpot commented Jun 27, 2019

Should be fixed by #1202.

@fabpot fabpot closed this as completed Jun 27, 2019
fabpot added a commit that referenced this issue Jun 27, 2019
…or before connect() (fabpot)

This PR was merged into the 6.2-dev branch.

Discussion
----------

Fix error message when connecting to a stream raises an error before connect()

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| Doc update?   | no
| BC breaks?    | no
| Deprecations? | no
| Fixed tickets | #1201
| License       | MIT

<!-- Replace this comment by the description of your issue. -->

Commits
-------

28a0e25 fixed error message when connecting to a stream raises an error before connect()
fabpot added a commit to symfony/symfony that referenced this issue Jun 27, 2019
…ses an error before connect() (fabpot)

This PR was merged into the 4.3 branch.

Discussion
----------

[Mailer] Fix error message when connecting to a stream raises an error before connect()

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | see swiftmailer/swiftmailer#1201
| License       | MIT
| Doc PR        | n/a

According to the PHP docs, "If the value returned in errno is 0 and the function returned FALSE, it is an indication that the error occurred before the connect() call.".

Using the `@` operator means that we get a generic error message without any clues about why connection cannot be done. Using an error handler allows to get the real issue.

Commits
-------

eb15bff [Mailer] fixed error message when connecting to a stream raises an error before connect()
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants