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

Bugifx: Index out of bounds in Server#extract_conn_info #803

Closed
wants to merge 11 commits into from

Conversation

spuun
Copy link
Member

@spuun spuun commented Oct 11, 2024

WHAT is this pull request doing?

When we try to autodetect proxy protocol version we sometimes get a Index ouf of bounds because there isn't enough data on the socket for IO::Buffered#peek to read, so our peek[x,y] call raises.

This will add an overload #peek(size) to IO::Buffered which will ensure the buffer contains at least size bytes.

Maybe we'll get something similar in the stdlib in the future: crystal-lang/crystal#15075

HOW can this pull request be tested?

Run specs to verify #peek(size)

@spuun spuun requested a review from a team as a code owner October 11, 2024 09:03
@spuun spuun mentioned this pull request Oct 11, 2024
@kickster97
Copy link
Member

When i try so send an MQTT ping without doing a proper connect first, i get stuck in peek and my client times out.
before, the connection factory was able to try and connect, and then send a connack letting the client know its not allowed.

@kickster97
Copy link
Member

also these look different now

2024-10-11T14:50:37.650125Z   INFO - lmq.server: Listening on [::1]:62815
2024-10-11T14:50:37.650135Z   INFO - lmq.server: Listening on [::1]:62814

@spuun
Copy link
Member Author

spuun commented Oct 11, 2024

When i try so send an MQTT ping without doing a proper connect first, i get stuck in peek and my client times out. before, the connection factory was able to try and connect, and then send a connack letting the client know its not allowed.

Probably related to read timeout in lavinmq.

I wonder if that spec is passing but for the wrong reason. I need to investigate that. I think the socket has been closed because of the bug this PR is trying to fix, not because the wrong mqtt packet was sent.

@spuun
Copy link
Member Author

spuun commented Oct 11, 2024

also these look different now

2024-10-11T14:50:37.650125Z   INFO - lmq.server: Listening on [::1]:62815
2024-10-11T14:50:37.650135Z   INFO - lmq.server: Listening on [::1]:62814

Different how? :)

@kickster97
Copy link
Member

also these look different now

2024-10-11T14:50:37.650125Z INFO - lmq.server: Listening on [::1]:62815

2024-10-11T14:50:37.650135Z INFO - lmq.server: Listening on [::1]:62814

Different how? :)

The [::1]:62815 i think... but maybe its just my spec 😅

@spuun
Copy link
Member Author

spuun commented Oct 12, 2024

The [::1]:62815 i think... but maybe its just my spec 😅

I think it's related to other changes, like the uniformed logging.

@carlhoerberg
Copy link
Member

I would probably just check the length of the peek buffer to avoid the indexerror. I dont know when only part of the Proxy protocol header would be sent, so if the buffer isnt long enough we can be certain that it isnt a a proxy protocol at least

@carlhoerberg
Copy link
Member

@spuun
Copy link
Member Author

spuun commented Oct 13, 2024

Yeah, but I thought it maybe could be a contribution to the stdlib.

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.

3 participants