-
Notifications
You must be signed in to change notification settings - Fork 35
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
Conversation
When i try so send an MQTT ping without doing a proper connect first, i get stuck in peek and my client times out. |
also these look different now
|
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. |
Different how? :) |
The [::1]:62815 i think... but maybe its just my spec 😅 |
I think it's related to other changes, like the uniformed logging. |
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 |
Actually, just use Slice#[]?, https://devdocs.io/crystal/slice#%5B%5D%3F%28start%3AInt%2Ccount%3AInt%29%3ASlice%28T%29%7CNil-instance-method |
Yeah, but I thought it maybe could be a contribution to the stdlib. |
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 forIO::Buffered#peek
to read, so ourpeek[x,y]
call raises.This will add an overload
#peek(size)
toIO::Buffered
which will ensure the buffer contains at leastsize
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)
…