-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Fix data loss in TCP streams. #2097
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 👍
app/modules/net.c
Outdated
num_args += 2; | ||
char iptmp[16]; | ||
bzero(iptmp, 16); | ||
ets_sprintf(iptmp, IPSTR, IP2STR(&addr->addr)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be moved outside a loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, though it becomes (slightly) harder to follow, and you double up on the if
statement as you'll need to push the port/ip each time through the loop regardless. Given that we'd normally be doing the ets_sprintf
for each pbuf anyway, I felt the tradeoff wasn't worth the readability cost. If you really reckon it is, I can change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree for "harder to follow"...
Will accept 'FIXME' comment there as a solution for now.
wondering if this patch could fix also the mysterious MQTT issues (where bits of TCP data were missing randomly) #1811 |
Afaiu mqtt uses espconn, so this shouldn't be applicable there. Someone is welcome to prove me wrong though :) |
* Fix data loss in TCP streams. * Factored out the UDP extra args handling.
* Fix data loss in TCP streams. * Factored out the UDP extra args handling.
dev
branch rather than formaster
.docs/en/*
.So it turns out that very occasionally^ the lwip stack hands over chained
pbuf
s to thetcp_recv()
callback. As only the firstpbuf
in the chain was passed into Lua, this meant that data went missing from the middle of the TCP stream (which one would certainly not expect). The fix here is to simply do multiple callbacks into Lua until the end of the chain is reached (though I've never seen more than twopbuf
s in the chain so far).With this patch I'm now always successfully getting the full TCP stream, whereas before I never did.
^) During each 1meg transfer, I saw it happen 1-4 times.