Please sign in to comment.
greenio: Remove sendall-like semantincs from GreenSocket.send
When a socket timeout was set the sendall-like semantics was resulting in losing information about sent data and raising socket.timeout exception. The previous GreenSocket.send() implementation used to call fd.send() in a loop until all data was sent. The issue would manifest if at least one fd.send() call succeeded and was followed by a fd.send() call that would block and a trampoline that timed out. The client code would see socket.timeout being raised and would rightfully assume that no data was sent which would be incorrect. Discussed at #260. The original commit has been reverted because it broke the test_multiple_readers test. After some debugging I believe I more or less know what's going on: The test uses sendall() which calls send() in a loop if send() reports only part of the data sent. Previously sendall() would call send() only one anyway because send() had sendall-like semantics; send has an internal loop on its own and, previously, it'd call the underlying socket object send() and, in case of partial write, call trampoline mechanism which would switch to another greenthread ready to run. After the change partial writes no longer result in trampoline mechanism being called which means that during this test it's likely that sendall() doesn't yield control to the hub even once. Similarly the current recv() implementation - it attemps to read from a socket first and only yields control to the hub if there's nothing to read at the moment; when one of the readers obtained control it's likely it'd manage to read all the data from the socket without yielding control to the hub and letting the other reader receive any data. The test changes the sending code so that it not only yields to the hub but also waits a bit so that both the readers have to yield to the hub when trying to read and there's no data available; the tests confirmed this lets both the readers receive some data from the socket which is the purpose of the test.  4656ead
- Loading branch information...
Showing with 9 additions and 10 deletions.