-
Notifications
You must be signed in to change notification settings - Fork 75
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
[Yamux] Fix sending of buffered messages after a window update #312
[Yamux] Fix sending of buffered messages after a window update #312
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.
LGTM
nit: TBH I would refactor this part
private val receiveWindows = ConcurrentHashMap<MuxId, AtomicInteger>()
private val sendWindows = ConcurrentHashMap<MuxId, AtomicInteger>()
private val sendBuffers = ConcurrentHashMap<MuxId, SendBuffer>()
private val totalBufferedWrites = AtomicInteger()
- Looks like we need just a single
Map<MuxId, *>
- Probably it makes sense to make
totalBufferedWrites
calculatable on the fly. Seems much safer while probably not that bad with respect to performance
|
||
fun add(data: ByteBuf) { | ||
buffered.add(data.retain()) | ||
bufferedData.add(data) |
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.
Right! It was excessive pair of retain/release.
Just to note: the general rule of sending the handler closest to the wire is responsible for releasing the message buffer
I think this introduces a vulnerability by merging the send and receive windows. A remote could send a window update for their own receive buffer id, and trick us into setting our receive window for them to a large value? |
@ianopolous thanks for that point 👍 |
I think it's a reasonable feedback. Could raise a PR for future discussion. |
Mainly changes and refactoring around
SendBuffer
class. Also using a singlewindowSizes
map for receive and send window sizes since the MuxId is different.Before logic was checking the total written bytes in the buffer against the
sendWindow
to determine if it fits within window. That is not entirely correct since the sendWindow is changed insidesendBlocks
method. That could lead to incorrect behaviour.Also there is a possibility that
sendWindow
is negative, so adding a check which will help with one of the exceptions captured in #311java.lang.IllegalArgumentException: minimumReadableBytes : -52227 (expected: >= 0)
Also change to calculate
totalBufferedWrites
on the fly based on the existingSendBuffer
values in the map.Removed
data.retain
anddata.release
inSendBuffer.add()
andSendBuffer.flush()
. Usedata.readRetainedSlice()
for the partial buffer sending.