fix partial send of outbound data #8
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We got a report from a customer that running a migration with diesel would hang.
After investigating, it seems running an insert query of approximately 25MiB would just hang.
I've tracked down the reason for it: the flow of our proxy is flawed. Basically, we wait on the "receiving" socket, in this migration case, the client, so that it sends data. We then construct our packet, and once this packet is complete, we intercept it and populate the "outbound" packet to be sent to the server (the packet sent by the client and intercepted).
However, we only call
Socket.sendonce there, and do the right thing by slicing theoutbounddata with what we really sent. However, to get to send again, we need the client to send more data. But the client is waiting for the server to respond, and the server hasn't received anything (or just a partial send, not a full query).Until we refactor the proxy deeper, the fix consist of iterating over the outbound data until there's none left. I've tested it locally and it solved the issue.
As an alternative solution, using
Socket.sendallcould also work, and we should then remove the whole logic around slicing theoutbounddata with thesentlength.