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

Add per-IP rate limiters #21

Merged
merged 1 commit into from
Dec 10, 2024
Merged

Add per-IP rate limiters #21

merged 1 commit into from
Dec 10, 2024

Conversation

ericvolp12
Copy link
Collaborator

Seeing some weird behavior where some consumers will reconnect very aggressively like multiple times a second and trigger huge playbacks but half close the connection and open a new one. This sucks and I'll start with a basic IP-wide rate limiter but may move to rejecting connections if I see too many for one IP at some point.

@uniphil
Copy link

uniphil commented Nov 17, 2024

oh no, i wonder if this was me. or partly from me. found my app crashed this morning with logs due to a bad event being served by the jetstream server:

2024-11-17T17:01:36.815 app[e82d661b006248] yyz [info] time=2024-11-17T17:01:36.815Z level=INFO source=/go/pkg/mod/github.com/bluesky-social/jetstream@v0.0.0-20241031234625-0ab10bd041fe/pkg/client/client.go:136 msg="starting websocket read loop" component=jetstream-client

2024-11-17T17:01:37.076 app[e82d661b006248] yyz [info] time=2024-11-17T17:01:37.076Z level=ERROR source=/go/pkg/mod/github.com/bluesky-social/jetstream@v0.0.0-20241031234625-0ab10bd041fe/pkg/client/client.go:175 msg="failed to unmarshal event" component=jetstream-client error="invalid character \"[\" exceeded max depth"

2024-11-17T17:01:37.076 app[e82d661b006248] yyz [info] time=2024-11-17T17:01:37.076Z level=ERROR source=/usr/src/app/consumer.go:143 msg="failed to connect" !BADKEY="read loop failed: failed to unmarshal event: invalid character \"[\" exceeded max depth"

edit: moved the rest with more context to #24 since this was off-topic for rate-limiting. sorry for the comment spam!

uniphil added a commit to uniphil/jetstream that referenced this pull request Nov 18, 2024
The existing code doesn't `defer c.con.Close()` and exits early if reading encounters any error -- so `.Close()` is never called on the connection. This change stores any read and closing errors, `Join`ing them on return, ensuring that `.Close()` is always called.

I'm not 100% sure but I hope this will help prevent the half-closed client connections referenced from bluesky-social#21

There is probably a more idiomatic way to do this (i am a go noob) but if i understand `errors.Join` and the current code, I think this should keep pretty close to the current intended behavior for any caller.
uniphil added a commit to uniphil/jetstream that referenced this pull request Nov 18, 2024
The existing code doesn't `defer c.con.Close()` and exits early if reading encounters any error -- so `.Close()` is never called on the connection. This change stores any read and closing errors, `Join`ing them on return, ensuring that `.Close()` is always called.

I'm not 100% sure but I hope this will help prevent the half-closed client connections referenced from bluesky-social#21

There is probably a more idiomatic way to do this (i am a go noob) but if i understand `errors.Join` and the current code, I think this should keep pretty close to the current intended behavior for any caller.
@ericvolp12 ericvolp12 marked this pull request as ready for review December 10, 2024 00:51
@ericvolp12 ericvolp12 merged commit ea96859 into main Dec 10, 2024
1 check passed
@ericvolp12 ericvolp12 deleted the jetstream_limiters branch December 10, 2024 00:51
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