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

Safe StreamEvents write loop #14557

Merged
merged 10 commits into from
Oct 24, 2024
Merged

Safe StreamEvents write loop #14557

merged 10 commits into from
Oct 24, 2024

Conversation

kasey
Copy link
Contributor

@kasey kasey commented Oct 18, 2024

What type of PR is this?
Bug fix

What does this PR do? Why is it needed?

StreamEvents handler now waits for the write loop to exit. In order to do this safely it uses the ResponseController type and calls SetWriteTimeout before each write (otherwise the write goroutine could get stuck blocked on the reader and wedge the http handler). Doing all this required some additional work on testing setup and support, in particular watching logs for errors since these are otherwise hard to detect with a streaming http response.

Which issues(s) does this PR fix?

Fixes #

Other notes for review

Acknowledgements

  • I have read CONTRIBUTING.md.
  • I have made an appropriate entry to CHANGELOG.md.
  • I have added a description to this PR with sufficient context for reviewers to understand this PR.

@kasey kasey requested a review from a team as a code owner October 18, 2024 17:44
beacon-chain/rpc/eth/events/events_test.go Outdated Show resolved Hide resolved
beacon-chain/rpc/eth/events/events_test.go Outdated Show resolved Hide resolved
@kasey kasey changed the title WIP: Safe StreamEvents write loop Safe StreamEvents write loop Oct 21, 2024
@kasey kasey force-pushed the safe-stream-write-loop branch from d69752c to 4e9d21a Compare October 21, 2024 20:21
@kasey kasey force-pushed the safe-stream-write-loop branch from 147fc08 to 338ffba Compare October 23, 2024 17:06
go es.outboxWriteLoop(ctx, cancel, sw)
if err := es.recvEventLoop(ctx, cancel, topics, s); err != nil {
log.WithError(err).Debug("Shutting down StreamEvents handler.")
}
cleanupStart := time.Now()
es.waitForCleanup()
Copy link
Contributor

Choose a reason for hiding this comment

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

for other reviewers, this is key to fixing the panic here. previously StreamEvents would exit and the outboxWriteLoop could still be writing to a writer that was cleaned up via regular HTTP processes. now there is this wait and inside the writes wrapped with deadlines

james-prysm
james-prysm previously approved these changes Oct 23, 2024
Comment on lines 200 to 203
defer close(es.outbox)
defer func() {
cancel()
}()
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you need es.exit() here. Otherwise this function will return with an error, the Shutting down StreamEvents handler log will be printed and the handler will be stuck on es.waitForExit() indefinitely because outboxWriteLoop will just keep looping. On the other hand, I am not sure if there aren't negative consequences of exiting here instead of in outboxWriteLoop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as discussed offline the context cancellation in recvEventLoop causes outboxWriteLoop to break out of the loop and call exit on its own.

rkapka
rkapka previously approved these changes Oct 24, 2024
james-prysm
james-prysm previously approved these changes Oct 24, 2024
@kasey
Copy link
Contributor Author

kasey commented Oct 24, 2024

Well, deep source is stuck, so I'm going to fix it's one complaint and push to try to start it again.

@kasey kasey dismissed stale reviews from james-prysm and rkapka via 80027ea October 24, 2024 18:07
@kasey kasey force-pushed the safe-stream-write-loop branch from 80027ea to 168b26a Compare October 24, 2024 18:08
james-prysm
james-prysm previously approved these changes Oct 24, 2024
prestonvanloon
prestonvanloon previously approved these changes Oct 24, 2024
testing/util/BUILD.bazel Outdated Show resolved Hide resolved
@@ -0,0 +1,90 @@
package util
Copy link
Member

Choose a reason for hiding this comment

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

Nice additions to this pkg!

@kasey kasey dismissed stale reviews from prestonvanloon and james-prysm via bf8a6c8 October 24, 2024 19:01
@kasey kasey added this pull request to the merge queue Oct 24, 2024
Merged via the queue into develop with commit 52cf3a1 Oct 24, 2024
18 checks passed
@kasey kasey deleted the safe-stream-write-loop branch October 24, 2024 19:23
@kasey kasey added the changelog/fixed Changelog Section: Fixed label Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog/fixed Changelog Section: Fixed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants