[libbeat/output/kafka]: fix panic on Publish after Close#46446
[libbeat/output/kafka]: fix panic on Publish after Close#46446AndersonQ merged 14 commits intoelastic:mainfrom
Conversation
🤖 GitHub commentsExpand to view the GitHub comments
Just comment with:
|
|
This pull request does not have a backport label.
To fixup this pull request, you need to add the backport labels for the needed
|
2ba2950 to
f82b26e
Compare
|
This pull request is now in conflicts. Could you fix it? 🙏 |
71a33cc to
cf2cb99
Compare
|
This pull request is now in conflicts. Could you fix it? 🙏 |
There was a problem hiding this comment.
Pull Request Overview
Fixes a race condition in the Kafka output client that could cause a panic during shutdown when Publish calls were in-flight while the client was closing.
- Adds proper channel close detection in the
Publishmethod to prevent sending on closed channels - Implements graceful event dropping with logging when the client is shutting down
- Adds a comprehensive test to reproduce and verify the fix for the race condition
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| libbeat/outputs/kafka/client.go | Adds select statement to handle closed channel during publish operations |
| libbeat/outputs/kafka/client_test.go | Adds test case to reproduce the shutdown panic scenario |
| CHANGELOG.next.asciidoc | Documents the bug fix in the changelog |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
cf2cb99 to
f45f415
Compare
A race condition during client shutdown could cause a panic. If a `Publish` call was in-flight while the client was closing, the underlying Kafka producer's input channel could be closed before the call finished sending all messages in the batch. The subsequent attempt to send the remaining messages on this closed channel would result in a panic.
f45f415 to
f6a6e31
Compare
|
Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane) |
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
This pull request is now in conflicts. Could you fix it? 🙏 |
|
This pull request is now in conflicts. Could you fix it? 🙏 |
This reverts commit 6fa4d61.
…6109-kafka-output-panic
|
@Mergifyio backport 8.18 8.19 9.0 9.1 |
✅ Backports have been createdDetails
|
* libbeat/output/kafka: fix panic on Publish after Close A race condition during client shutdown could cause a panic. If a `Publish` call was in-flight while the client was closing, the underlying Kafka producer's input channel could be closed before the call finished sending all messages in the batch. The subsequent attempt to send the remaining messages on this closed channel would result in a panic. (cherry picked from commit bc05117)
* libbeat/output/kafka: fix panic on Publish after Close A race condition during client shutdown could cause a panic. If a `Publish` call was in-flight while the client was closing, the underlying Kafka producer's input channel could be closed before the call finished sending all messages in the batch. The subsequent attempt to send the remaining messages on this closed channel would result in a panic. (cherry picked from commit bc05117)
* libbeat/output/kafka: fix panic on Publish after Close A race condition during client shutdown could cause a panic. If a `Publish` call was in-flight while the client was closing, the underlying Kafka producer's input channel could be closed before the call finished sending all messages in the batch. The subsequent attempt to send the remaining messages on this closed channel would result in a panic. (cherry picked from commit bc05117)
* libbeat/output/kafka: fix panic on Publish after Close A race condition during client shutdown could cause a panic. If a `Publish` call was in-flight while the client was closing, the underlying Kafka producer's input channel could be closed before the call finished sending all messages in the batch. The subsequent attempt to send the remaining messages on this closed channel would result in a panic. (cherry picked from commit bc05117)
…after Close (#46710) A race condition during client shutdown could cause a panic. If a `Publish` call was in-flight while the client was closing, the underlying Kafka producer's input channel could be closed before the call finished sending all messages in the batch. The subsequent attempt to send the remaining messages on this closed channel would result in a panic. (cherry picked from commit bc05117) * fix changelog --------- Co-authored-by: Anderson Queiroz <anderson.queiroz@elastic.co>
…after Close (#46709) A race condition during client shutdown could cause a panic. If a `Publish` call was in-flight while the client was closing, the underlying Kafka producer's input channel could be closed before the call finished sending all messages in the batch. The subsequent attempt to send the remaining messages on this closed channel would result in a panic. (cherry picked from commit bc05117) * fix changelog * fix test --------- Co-authored-by: Anderson Queiroz <anderson.queiroz@elastic.co>
…fter Close (#46712) A race condition during client shutdown could cause a panic. If a `Publish` call was in-flight while the client was closing, the underlying Kafka producer's input channel could be closed before the call finished sending all messages in the batch. The subsequent attempt to send the remaining messages on this closed channel would result in a panic. (cherry picked from commit bc05117) * fix changelog --------- Co-authored-by: Anderson Queiroz <anderson.queiroz@elastic.co>
…fter Close (#46711) A race condition during client shutdown could cause a panic. If a `Publish` call was in-flight while the client was closing, the underlying Kafka producer's input channel could be closed before the call finished sending all messages in the batch. The subsequent attempt to send the remaining messages on this closed channel would result in a panic. (cherry picked from commit bc05117) * fix changelog * fix test --------- Co-authored-by: Anderson Queiroz <anderson.queiroz@elastic.co>
Proposed commit message
Checklist
[ ] I have made corresponding changes to the documentation[ ] I have made corresponding change to the default configuration filesCHANGELOG.next.asciidocorCHANGELOG-developer.next.asciidoc.Disruptive User Impact
How to test this PR locally
try the steps described in the bug Filebeat panics when attempting to shutdown while using Kafka output #46109: (they did not work for me)
copy the new test, run it on main, you'll see the panic
Related issues