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

[bugfix] fix possible mutex lockup during streaming code #2633

Merged

Conversation

NyaaaWhatsUpDoc
Copy link
Member

Description

This fixes an issue I have noticed a few times on my own instance. It rewrites Stream{} to use much less mutex locking, and updates related code calling it.

Checklist

  • I/we have read the GoToSocial contribution guidelines.
  • I/we have discussed the proposed changes already, either in an issue on the repository, or in the Matrix chat.
  • I/we have not leveraged AI to create the proposed changes.
  • I/we have performed a self-review of added code.
  • I/we have written code that is legible and maintainable by others.
  • I/we have commented the added code, particularly in hard-to-understand areas.
  • I/we have made any necessary changes to documentation.
  • I/we have added tests that cover new code.
  • I/we have run tests and they pass locally with the changes.
  • I/we have run go fmt ./... and golangci-lint run.

Copy link
Member

@daenney daenney left a comment

Choose a reason for hiding this comment

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

The storing a context on the Stream feels wrong. It's something the context package warns against doing and the Go team wrote a whole blog post about. We might have a good reason for it, but I don't know what the motivation for it is and why it has to be done this way.

internal/api/client/streaming/stream.go Outdated Show resolved Hide resolved
internal/api/client/streaming/stream.go Show resolved Hide resolved
internal/api/client/streaming/stream.go Show resolved Hide resolved
@NyaaaWhatsUpDoc
Copy link
Member Author

NyaaaWhatsUpDoc commented Feb 12, 2024

The storing a context on the Stream feels wrong. It's something the context package warns against doing and the Go team wrote a whole blog post about. We might have a good reason for it, but I don't know what the motivation for it is and why it has to be done this way.

ah i wasn't aware of this. will have a think about rearchitecting it, and mark it draft for now. specifically it's the 'Done()' channel part of the context that's a useful piece of logic for tracking only-once pieces of behaviour like closing and being able to select against it, but i suppose i can just use a channel separately for that. (that was actually what i did in previous iterations of this code but i ended up going with context.Context because reasons i can't remember)

have rearchitected with this now in mind :)

@NyaaaWhatsUpDoc NyaaaWhatsUpDoc marked this pull request as draft February 12, 2024 15:52
@NyaaaWhatsUpDoc NyaaaWhatsUpDoc marked this pull request as ready for review February 19, 2024 13:17
@NyaaaWhatsUpDoc
Copy link
Member Author

just wanna make one last change, changing to draft until then even though all tests are passing

@NyaaaWhatsUpDoc NyaaaWhatsUpDoc marked this pull request as draft February 19, 2024 14:10
@NyaaaWhatsUpDoc NyaaaWhatsUpDoc marked this pull request as ready for review February 19, 2024 19:06
internal/api/client/streaming/stream.go Show resolved Hide resolved
internal/processing/stream/notification.go Outdated Show resolved Hide resolved
internal/processing/stream/statusupdate.go Outdated Show resolved Hide resolved
internal/processing/stream/update.go Outdated Show resolved Hide resolved
@NyaaaWhatsUpDoc NyaaaWhatsUpDoc merged commit 291e180 into superseriousbusiness:main Feb 20, 2024
2 checks passed
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.

2 participants