-
Notifications
You must be signed in to change notification settings - Fork 2
Fix thread not waking up when there is still data to be sent #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
880fe0e to
42c6f8e
Compare
| conn.send(req2, blocking=False) | ||
| # This will send the remaining bytes in the buffer from the first request, but should notice | ||
| # that the second request was queued, therefore it should return False. | ||
| assert conn.send_pending_requests_v2() is False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where the test would fail before the fix.
|
I think the PR is fine. But I'd like to somebody like e.g. @aiven-anton to have a look at it too. The PR touches Thus, not approving/merging. |
aiven-anton
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not well versed in this code-base, but this seems like a well thought-through fix and I cannot spot any real issues with it. It seems sound to move ahead with this.
We should also notify the upstream(s) of this issue and fix.
I left two minor comments, let me know if you want to address those.
When producing messages quickly without waiting for the future of previous requests, there could be some situations when the last batch was not sent. That seemed to be more frequent with larger messages (~100KiB), but apparently it could happen to any message when `linger_ms` is 0. Not sure if it could happen when it is non-zero though. The reason is that `BrokerConnection.send_pending_requests_v2` would fill the internal buffer with the bytes from a request and try to send it. https://github.com/aiven/kafka-python/blob/e0ab864f7aca3961e729cf03d1caa3899fbee617/kafka/conn.py#L1036 If it couldn't send it completely for some reason, it would try to send again in the next call to `send_pending_requests_v2`. But if between those 2 calls, `BrokerConnection.send` was called, new data would be appended to self._protocol: KafkaProtocol: https://github.com/aiven/kafka-python/blob/b01ffb6a004480635751e325db2ded20bcdc0d2f/kafka/conn.py#L981 but the second call to `send_pending_requests_v2` wouldn't check if any new data was available and would return False: https://github.com/aiven/kafka-python/blob/e0ab864f7aca3961e729cf03d1caa3899fbee617/kafka/conn.py#L1035 This would tell `KafkaClient._poll` that all pending data was sent, which would make the client not listen to socked write readiness anymore: https://github.com/aiven/kafka-python/blob/b01ffb6a004480635751e325db2ded20bcdc0d2f/kafka/client_async.py#L663-L667
42c6f8e to
719cf45
Compare
|
After this is merged, I'll open a PR in the upstream repo |
Upstream PR: dpkp#2670 |
When producing messages quickly without waiting for the future of previous requests, there could be some situations when the last batch was not sent.
That seemed to be more frequent with larger messages (~100KiB), but apparently it could happen to any message when
linger_msis 0. Not sure if it could happen when it is non-zero though.The reason is that
BrokerConnection.send_pending_requests_v2would fill the internal buffer with the bytes from a request and try to send it.kafka-python/kafka/conn.py
Line 1036 in e0ab864
If it couldn't send it completely for some reason, it would try to send again in the next call to
send_pending_requests_v2.But if between those 2 calls,
BrokerConnection.sendwas called, new data would be appended to self._protocol: KafkaProtocol:kafka-python/kafka/conn.py
Line 981 in b01ffb6
but the second call to
send_pending_requests_v2wouldn't check if any new data was available and would return False:kafka-python/kafka/conn.py
Line 1035 in e0ab864
This would tell
KafkaClient._pollthat all pending data was sent, which would make the client not listen to socked write readiness anymore:kafka-python/kafka/client_async.py
Lines 663 to 667 in b01ffb6