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

Wrap socket_* calls with error-catching handlers #138

Closed
asgrim opened this issue Dec 16, 2019 · 0 comments · Fixed by #144
Closed

Wrap socket_* calls with error-catching handlers #138

asgrim opened this issue Dec 16, 2019 · 0 comments · Fixed by #144
Assignees
Labels
enhancement New feature or request

Comments

@asgrim
Copy link
Collaborator

asgrim commented Dec 16, 2019

At the moment in \Scoutapm\Connector\SocketConnector::sendCommand() for example, if there is a broken pipe, we get an error raised, for example:

[2019-12-16 13:30:58] local.ERROR: socket_send(): unable to write to socket [32]: Broken pipe {"exception":"[object] (ErrorException(code: 0): socket_send(): unable to write to socket [32]: Broken pipe at /home/james/workspace/scout-apm-laravel-blog/vendor/scoutapp/scout-apm-php/src/Connector/SocketConnector.php:103)
[stacktrace]
#0 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(2, 'socket_send(): ...', '/home/james/wor...', 103, Array)
#1 /home/james/workspace/scout-apm-laravel-blog/vendor/scoutapp/scout-apm-php/src/Connector/SocketConnector.php(103): socket_send(Resource id #323, '\\x00\\x00\\x00e', 4, 0)
#2 /home/james/workspace/scout-apm-laravel-blog/vendor/scoutapp/scout-apm-php/src/Agent.php(320): Scoutapm\\Connector\\SocketConnector->sendCommand(Object(Scoutapm\\Events\\RegisterMessage))

Write a private function that adds an error handler to convert errors to exceptions (and use socket_last_error / socket_strerror to retrieve additional potentially useful error details) and bubble up to provide a more controlled error/exception flow.

The wrapped call to socket_connect in \Scoutapm\Connector\SocketConnector::connect can also be converted to use this new function.

@asgrim asgrim added the enhancement New feature or request label Dec 16, 2019
@asgrim asgrim self-assigned this Dec 16, 2019
@asgrim asgrim changed the title Wrap socket_* commands with error-catching handlers Wrap socket_* calls with error-catching handlers Dec 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant