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 peer handler race #965

Merged
merged 1 commit into from Jun 5, 2020
Merged

Fix peer handler race #965

merged 1 commit into from Jun 5, 2020

Conversation

Stebalien
Copy link
Member

Alternative to #963. Instead of using atomics, this patch ensures that all state changes are performed on the main thread. It also:

  • Threads the context through explicitly to make sure fields changed by the main thread are never read by the handler goroutines. This isn't strictly necessary but it makes it easier to reason about.
  • Uses a callback to signal "on done". There may be cleaner ways to do this (I hate callbacks), but this nicely decouples the peer handler from the main loop.

fixes #963

Copy link
Contributor

@vyzo vyzo left a comment

Choose a reason for hiding this comment

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

there is nothing wrong with callbacks when used properly :)

Alternative to #963. Instead of using atomics, this patch ensures that all state
changes are performed on the main thread. It also:

* Threads the context through explicitly to make sure fields changed by the main
thread are never read by the handler goroutines. This isn't strictly necessary
but it makes it easier to reason about.
* Uses a callback to signal "on done". There may be cleaner ways to do this (I
hate callbacks), but this nicely decouples the peer handler from the main loop.

fixes #963
Copy link
Contributor

@aarshkshah1992 aarshkshah1992 left a comment

Choose a reason for hiding this comment

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

Beautiful.

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.

None yet

3 participants