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

Resume the connection after exception #193

Closed
caucik opened this issue May 1, 2019 · 1 comment
Closed

Resume the connection after exception #193

caucik opened this issue May 1, 2019 · 1 comment
Labels

Comments

@caucik
Copy link

caucik commented May 1, 2019

After the exception in thrown the socket connection can no longer be properly closed nor resumed. See Close behavior.

@clue clue added the question label May 1, 2019
@clue
Copy link
Member

clue commented May 1, 2019

@caucik Thanks for reporting, I understand where you're coming from. Throwing an exception from any listener is not allowed:

The listener callback function MUST NOT throw an Exception. The return value of the listener callback function will be ignored and has no effect, so for performance reasons you're recommended to not return any excessive data structures.

https://github.com/reactphp/event-loop#addreadstream

As an alternative, I would recommend either letting the uncaught exception crash your application like it appears to do right now or if you want to handle it, wrapping your event handler code in a try-catch-block like this:

$loop->addPeriodicTimer(3.0, function () {
    try {
        apiThatMightThrow();
    } catch (Exception $e) {
        // exception is non-fatal here, we simply log and wait for next iteration
        logException($e);
    }
});

I hope this helps 👍

@clue clue closed this as completed May 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants