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

Fix buffered chan event system #3968

Merged
merged 1 commit into from
Sep 25, 2024
Merged

Conversation

ankur22
Copy link
Contributor

@ankur22 ankur22 commented Sep 24, 2024

What?

This removes the default case for when reading done events from the extension or when sending events to the extension.

Why?

If we drop events due to the channel being full and there being a default case, then we can end up in a situation where either the event system indefinitely waits since incoming done events were not handled by the event system or the extension waits indefinitely if the event was dropped when sending it the event.

Checklist

  • I have performed a self-review of my code.
  • I have added tests for my changes.
  • I have run linter locally (make lint) and all checks pass.
  • I have run tests locally (make tests) and all tests pass.
  • I have commented on my code, particularly in hard-to-understand areas.

Related PR(s)/Issue(s)

grafana/xk6-browser#1440

@ankur22 ankur22 requested a review from a team as a code owner September 24, 2024 15:06
@ankur22 ankur22 requested review from mstoykov, joanlopez and inancgumus and removed request for a team September 24, 2024 15:06
If we drop events due to the default case then we can end up in a
situation where either the event system indefinitely waits since done
events were not handled or the extension waits indefinitely if the
event was dropped when sending it the event.
@ankur22 ankur22 force-pushed the fix/buffered-chan-event-system branch from 4965154 to d0781c6 Compare September 24, 2024 15:07
Copy link
Member

@inancgumus inancgumus left a comment

Choose a reason for hiding this comment

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

LGTM 👍 One point to keep in mind: More calls to Done than the number of subscribers will again block :)

@ankur22
Copy link
Contributor Author

ankur22 commented Sep 25, 2024

One point to keep in mind: More calls to Done than the number of subscribers will again block :)

Yeah, that's a good point. I hadn't considered the reason why there was a default in the first place.

Having looked at this again, I still feel that this is the correct approach. Dropping done events or the events going to the extension will mean that one of the two will misbehave, either the extension will hang indefinitely or k6 will.

In the extension side (i.e. in browser) we could call e.Done() on a goroutine for the exit event. We don't want the browser module to hang around waiting for e.Done() to complete, so feels like a safe option. In my tests so far i've not needed to do this though, so i'd avoid doing that for now.

There is the chance that the subscriber could have called subscribe twice and handle the same subscription in the same goroutine, this could cause a deadlock (I think). This feels like user error though.

@ankur22 ankur22 merged commit 86ab6e3 into master Sep 25, 2024
22 checks passed
@ankur22 ankur22 deleted the fix/buffered-chan-event-system branch September 25, 2024 10:02
ankur22 added a commit to grafana/xk6-browser that referenced this pull request Sep 25, 2024
ankur22 added a commit to grafana/xk6-browser that referenced this pull request Sep 25, 2024
ankur22 added a commit to grafana/xk6-browser that referenced this pull request Sep 25, 2024
ankur22 added a commit to grafana/xk6-browser that referenced this pull request Sep 25, 2024
@olegbespalov olegbespalov added this to the v0.54.0 milestone Sep 26, 2024
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.

4 participants