forked from apache/cassandra-gocql-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make write to connection cancellable
There were a few issues with the original implementation: - deadlineWriter didn't use a critical section around SetWriteDeadline/Write pair, so an incoming writer moved the deadline for pending writes. - There was a lock around Write in the writeCoalescer implementation. This means that all goroutines trying to write to the connection could be stuck if Write blocks (i.e. when the TCP buffer is full, probably because of the remote node not reading fast enough). - If a write was queued before the long Write call, it would be added to buffers (I'm not sure if an attempt would be made to write it before the connection is closed, but it seems possible). When a connection is stuck in Write and there are other writes queueing up, we want to abort them if the context is canceled and the write waiting in queue was not started yet. We can't cancel writes that are blocked in Write when the context is canceled because context can be canceled due to external factors like a user disconnecting. Canceling the pending Write could result in partial write of a frame, clobbering the connection state. Added checks for SetWriteDeadline errors, since not setting the deadline could stuck the write goroutines potentially for infinitely long, so it seems better to just return error. It seems that SetWriteDeadline could fail only if the network connection does not use a facility like epoll, which is highly unlikely. I found checked Go code and as far as I can tell, only some file descriptors other that network connections don't support the deadline. Also added correct return values (written byte count) since returning 0 when an error is made is misleading.
- Loading branch information
1 parent
344f583
commit 830d6d0
Showing
2 changed files
with
212 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.