Random huge delays, after sending a message out getting the response taking to match time ~5s in some cases
Main session loop is either sending a batch (and blocking until all messages in the batch are sent) or reading just ONE incoming message.
So, if there are many messages in the slice toSend, session from our side is blocked until all the messages are sent.
At the same time, if halfway (when half of the messages in toSend have been sent) the other side cannot accept more messages (maybe cause of a buffer overflow) in order to be unblocked, we need to consume some of the incoming messages, which with the current implementation cannot happen.
Proposed solution
When sending queued messages, if any of the messages cannot be sent, then we escape the toSend loop and leave the rest of the messages for the next session loop.
Issue
Observations
session.sendMutex
So, if there are many messages in the slice
toSend
, session from our side is blocked until all the messages are sent. At the same time, if halfway (when half of the messages intoSend
have been sent) the other side cannot accept more messages (maybe cause of a buffer overflow) in order to be unblocked, we need to consume some of the incoming messages, which with the current implementation cannot happen.Proposed solution
When sending queued messages, if any of the messages cannot be sent, then we escape the
toSend
loop and leave the rest of the messages for the next session loop.