use sendall vs send which does not guarentee all bytes will be sent#9
Merged
sevein merged 1 commit intoartefactual-labs:mainfrom Mar 5, 2026
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In clamav_client.clamd there are three uses of self.clamd_socket.send. Socket.send is a low-level function which does not (necessarily, by contract) send the entire buffer. Instead it returns the number of bytes actually sent, and the caller is required to manage the unsent bytes by passing them to socket.send until all are sent.
from the python spec for send: https://docs.python.org/3/library/socket.html#socket.socket.send
Send data to the socket. The socket must be connected to a remote socket. The optional flags argument has the same meaning as for recv() above. Returns the number of bytes sent. Applications are responsible for checking that all data has been sent; if only some of the data was transmitted, the application needs to attempt delivery of the remaining data.
compare to sendall: https://docs.python.org/3/library/socket.html#socket.socket.sendall
Unlike send(), this method continues to send data from bytes until either all data has been sent or an error occurs.
In the existing code, the return value from socket.send is not checked. This is something the library generally "gets away with" since it is sending at most 1024 bytes per send. However under gevent this is causing failures since the threads are changed more frequently. So we're seeing the impact of this defect (as was the author of this PR in 2021 against the source repo of clamd: graingert#23).
The PR presented replaces the low-level "send" call with the required "sendall" call which behaves as the code appears to expect.