Commit 84c5e74
authored
Fix write lock deadline handling (#7)
## Issue
The existing code in go-algorand is using two go-routines for reading/writing and a separate go-routine for opening/closing the connections.
When a client connection becomes non-responsive ( i.e. the writer is not returning ), the current implementation tries to close the connection. However, per WebSocket specification, the client is supposed to send a Close message first.
The close message is being sent using the `WriteControl` method, which is supposed to be able to run concurrently with `WriteMessage`. However, both reaches `Conn.write` where it attempt to acquire a writing lock.
Since the `WriteMessage -> Conn.write` is stuck ( but the `WriteControl` doesn't really know it's stuck indefinitely ), the `WriteControl -> Conn.write` get blocks indefinitely as well.
Unlike the `WriteMessage`, when calling `WriteControl`, we provide a deadline : a timestamp after which we don't care if the message was actually sent. In this PR, I have added handling that would limit the time the `Conn.write` would wait to that deadline.
From spec perspective, it would be a violation of the WebSocket protocol; however, given that the other party is no longer responsive, a successful writing of a Close message is not possible, it would probably be just fine.1 parent 19af735 commit 84c5e74
1 file changed
+34
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
93 | 97 | | |
94 | 98 | | |
95 | 99 | | |
| |||
428 | 432 | | |
429 | 433 | | |
430 | 434 | | |
431 | | - | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
432 | 465 | | |
433 | 466 | | |
434 | 467 | | |
| |||
0 commit comments