-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Close chan of Closer first before calling callback #14231
Conversation
Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually? |
1 similar comment
Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually? |
@vjsamuel Looking at the code of the TCP Input, I think you are right if we move the close of the channel. Now Looking at the TCP input code beats/filebeat/inputsource/tcp/handler.go Lines 99 to 104 in b089094
The select will also need to happen even if we don't get an error for this to works as expected. Now by closing the channel before the callback the following events will make the the handle stop:
|
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.
should have done the above comment with request changed.
filebeat/inputsource/tcp/closeref.go
Outdated
close(c.done) | ||
|
||
// TODO: callbacks that do socket closing would need to somehow synchronize the finish | ||
// TODO: of Handle() and then do the close to avoid reading from closed connection. |
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.
Lets remove the TODO here.
495637a
to
549a4aa
Compare
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.
Remove the comment and LGTM,
filebeat/inputsource/tcp/handler.go
Outdated
@@ -94,15 +94,25 @@ func (c *splitHandler) Handle(closer CloseRef, conn net.Conn) error { | |||
//16 is ratio of MaxScanTokenSize/startBufSize | |||
buffer := make([]byte, c.maxMessageSize/16) | |||
scanner.Buffer(buffer, int(c.maxMessageSize)) | |||
for scanner.Scan() { | |||
for { | |||
// we are forcing a Close on the socket, lets ignore any error that could happen. |
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 comment doesn't fit here, lets remove it.
Calling the callback first before closing the channel is causing
read from closed connection exceptions
. Ideally the processing should stop first before callingClose()
on the tcp connection.