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

fb_mqtt_cb_read: change read size to be remz, hopefully fixing timeouts #17

Merged
merged 1 commit into from
Mar 11, 2015

Conversation

dequis
Copy link
Member

@dequis dequis commented Mar 11, 2015

It was mqtt->rbuf->len previously, the length of the bytearray, which doesn't make a lot of sense - it resulted in reading 2, 4, 8, 16, 32 bytes and when it reached a high enough number, ssl_read would either:

  1. Stop because the socket buffer got empty (the main reason it kinda worked most of the time), or
  2. Continue reading into the next packet

And continuing to read means not just a desync but also that remz - rize (remaining bytes - read bytes) is negative, or more precisely, a huge number, since remz is unsigned.

So it gets stuck reading ~2**64 bytes into that buffer, thinking it's a neverending packet, and that means not getting pongs. So it timeouts.

The fix is trivial - just make it read exactly the amount of bytes it needs to read (remz), never more than that.

Fixes #2

It was mqtt->rbuf->len previously, the length of the bytearray, which
doesn't make a lot of sense - it resulted in reading 2, 4, 8, 16, 32
bytes and when it reached a high enough number, ssl_read would either:

1. Stop because the socket buffer got empty (the main reason it kinda
worked most of the time), or
2. Continue reading into the next packet

And continuing to read means not just a desync but also that remz - rize
(remaining bytes - read bytes) is negative, or more precisely, a huge
number, since remz is unsigned.

So it gets stuck reading ~2**64 bytes into that buffer, thinking it's a
neverending packet, and that means not getting pongs. So it timeouts.

The fix is trivial - just make it read exactly the amount of bytes it
needs to read (remz), never more than that.
@zopieux
Copy link
Contributor

zopieux commented Mar 11, 2015

Oh my god I love you.

@jgeboski jgeboski merged commit 059b686 into bitlbee:development Mar 11, 2015
@jgeboski
Copy link
Member

Kudos! Pretty bad oversight on my behalf.

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.

None yet

3 participants