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

Panic on RegisterCallback result being used more than once #2582

Merged
merged 1 commit into from
Jul 7, 2022

Conversation

mstoykov
Copy link
Contributor

This should help with actually finding problems with code using it.

I have already seen multiple times code which seems okay but in fact
will call the returned callback twice. This effectively will lead either
to deadlock of the eventloop or earlier exit from a loop.

Given that it's never actually correct to that, panic seems okay.

We also make certain that if the user recovers from the panic we will
not have locked the eventloop either way,

In the future better APIs for most use cases should probably reduce the
need for people to use RegisterCallback and consequently worrying about
this.

@mstoykov mstoykov added this to the v0.41.0 milestone Jun 30, 2022
@mstoykov mstoykov requested review from imiric and na-- June 30, 2022 11:31
@mstoykov mstoykov modified the milestones: v0.41.0, v0.40.0 Jun 30, 2022
js/eventloop/eventloop.go Outdated Show resolved Hide resolved
na--
na-- previously approved these changes Jun 30, 2022
Copy link
Member

@na-- na-- left a comment

Choose a reason for hiding this comment

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

LGTM in general, besides the naming nitpick. And I agree, the real solution would be less footgun-prone API like #2544 😅

This should help with actually finding problems with code using it.

I have already seen multiple times code which seems okay but in fact
will call the returned callback twice. This effectively will lead either
to deadlock of the eventloop or earlier exit from a loop.

Given that it's never actually correct to that, panic seems okay.

We also make certain that if the user recovers from the panic we will
not have locked the eventloop either way,

In the future better APIs for most use cases should probably reduce the
need for people to use RegisterCallback and consequently worrying about
this.
Copy link
Contributor

@imiric imiric left a comment

Choose a reason for hiding this comment

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

Makes sense 👍

@mstoykov mstoykov merged commit 4fdfea4 into master Jul 7, 2022
@mstoykov mstoykov deleted the panicOnSecondCallback branch July 7, 2022 06:46
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