Skip to content
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

tcp/unix input: Stop accepting connections after socket is closed #29712

Merged

Conversation

andrewkroh
Copy link
Member

@andrewkroh andrewkroh commented Jan 5, 2022

What does this PR do?

Stop accepting connections after tcp/unix socket is closed. This will suppress debug messages for net.ErrClosed.

2021-12-22T13:49:04.151Z	INFO	[tcp]	streaming/listener.go:172	StoppingTCPserver	{"address": "0.0.0.0:7000"}
2021-12-22T13:49:04.151Z	DEBUG	[tcp]	streaming/listener.go:129	Can not accept the connection	{"address": "0.0.0.0:7000", "error": "accept tcp [::]:7000: use of closed network connection"}

Why is it important?

This makes the shutdown process a little bit cleaning from a logging perspective.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

Logs

Sample log output of a starting, accepting a connection, disconnecting, and shutting down.

{
  "log.level": "info",
  "@timestamp": "2022-01-05T15:56:53.293-0500",
  "log.logger": "syslog",
  "log.origin": {
    "file.name": "syslog/input.go",
    "file.line": 147
  },
  "message": "Starting Syslog input",
  "service.name": "filebeat",
  "protocol": "tcp",
  "ecs.version": "1.6.0"
}
{
  "log.level": "debug",
  "@timestamp": "2022-01-05T15:56:53.293-0500",
  "log.logger": "tcp",
  "log.origin": {
    "file.name": "streaming/listener.go",
    "file.line": 141
  },
  "message": "Start accepting connections",
  "service.name": "filebeat",
  "address": "127.0.0.1:7000",
  "ecs.version": "1.6.0"
}
{
  "log.level": "debug",
  "@timestamp": "2022-01-05T15:56:58.775-0500",
  "log.logger": "tcp",
  "log.origin": {
    "file.name": "streaming/listener.go",
    "file.line": 185
  },
  "message": "New client connection.",
  "service.name": "filebeat",
  "address": "127.0.0.1:7000",
  "remote_address": "127.0.0.1:62085",
  "active_clients": 1,
  "ecs.version": "1.6.0"
}
{
  "log.level": "debug",
  "@timestamp": "2022-01-05T15:56:58.776-0500",
  "log.logger": "tcp",
  "log.origin": {
    "file.name": "streaming/listener.go",
    "file.line": 188
  },
  "message": "Client disconnected.",
  "service.name": "filebeat",
  "address": "127.0.0.1:7000",
  "remote_address": "127.0.0.1:62085",
  "active_clients": 0,
  "ecs.version": "1.6.0"
}
{
  "log.level": "debug",
  "@timestamp": "2022-01-05T15:57:02.287-0500",
  "log.logger": "tcp",
  "log.origin": {
    "file.name": "streaming/listener.go",
    "file.line": 200
  },
  "message": "Stopping socket listener. Waiting for all connections to close.",
  "service.name": "filebeat",
  "address": "127.0.0.1:7000",
  "ecs.version": "1.6.0"
}
{
  "log.level": "debug",
  "@timestamp": "2022-01-05T15:57:02.287-0500",
  "log.logger": "tcp",
  "log.origin": {
    "file.name": "streaming/listener.go",
    "file.line": 151
  },
  "message": "Stopped accepting connections",
  "service.name": "filebeat",
  "address": "127.0.0.1:7000",
  "ecs.version": "1.6.0"
}
{
  "log.level": "info",
  "@timestamp": "2022-01-05T15:57:02.287-0500",
  "log.logger": "tcp",
  "log.origin": {
    "file.name": "streaming/listener.go",
    "file.line": 203
  },
  "message": "Socket listener stopped",
  "service.name": "filebeat",
  "address": "127.0.0.1:7000",
  "ecs.version": "1.6.0"
}

@andrewkroh andrewkroh added bug Filebeat Filebeat Team:Security-External Integrations Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team backport-v8.1.0 Automated backport with mergify labels Jan 5, 2022
@botelastic botelastic bot added needs_team Indicates that the issue/PR needs a Team:* label and removed needs_team Indicates that the issue/PR needs a Team:* label labels Jan 5, 2022
@andrewkroh andrewkroh force-pushed the bugfix/fb/handle-net-err-closed-tcp-input branch 2 times, most recently from 5acaf12 to ec60086 Compare January 5, 2022 20:58
@andrewkroh andrewkroh marked this pull request as ready for review January 5, 2022 20:59
@elasticmachine
Copy link
Collaborator

Pinging @elastic/security-external-integrations (Team:Security-External Integrations)

@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

@elasticmachine
Copy link
Collaborator

elasticmachine commented Jan 5, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Reason: null

  • Start Time: 2022-02-04T00:20:36.187+0000

  • Duration: 104 min 46 sec

  • Commit: 777767b

Test stats 🧪

Test Results
Failed 0
Passed 9638
Skipped 1289
Total 10927

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /package : Generate the packages and run the E2E tests.

  • /beats-tester : Run the installation tests with beats-tester.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@andrewkroh
Copy link
Member Author

Looks like I broke some system tests that look for particular log messages.

@mergify
Copy link
Contributor

mergify bot commented Jan 11, 2022

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b bugfix/fb/handle-net-err-closed-tcp-input upstream/bugfix/fb/handle-net-err-closed-tcp-input
git merge upstream/master
git push upstream bugfix/fb/handle-net-err-closed-tcp-input

Stop accepting connections after tcp/unix socket is closed. This will suppress debug messages for net.ErrClosed.

    2021-12-22T13:49:04.151Z	INFO	[tcp]	streaming/listener.go:172	StoppingTCPserver	{"address": "0.0.0.0:7000"}
    2021-12-22T13:49:04.151Z	DEBUG	[tcp]	streaming/listener.go:129	Can not accept the connection	{"address": "0.0.0.0:7000", "error": "accept tcp [::]:7000: use of closed network connection"}
@andrewkroh andrewkroh force-pushed the bugfix/fb/handle-net-err-closed-tcp-input branch from b570394 to 0563606 Compare January 13, 2022 04:10
@andrewkroh
Copy link
Member Author

/test

@mergify
Copy link
Contributor

mergify bot commented Jan 24, 2022

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b bugfix/fb/handle-net-err-closed-tcp-input upstream/bugfix/fb/handle-net-err-closed-tcp-input
git merge upstream/master
git push upstream bugfix/fb/handle-net-err-closed-tcp-input

@andrewkroh
Copy link
Member Author

/test

@mergify
Copy link
Contributor

mergify bot commented Jan 25, 2022

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b bugfix/fb/handle-net-err-closed-tcp-input upstream/bugfix/fb/handle-net-err-closed-tcp-input
git merge upstream/master
git push upstream bugfix/fb/handle-net-err-closed-tcp-input

@andrewkroh
Copy link
Member Author

/test

@andrewkroh andrewkroh requested a review from a team January 27, 2022 13:31
@mergify
Copy link
Contributor

mergify bot commented Feb 1, 2022

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b bugfix/fb/handle-net-err-closed-tcp-input upstream/bugfix/fb/handle-net-err-closed-tcp-input
git merge upstream/master
git push upstream bugfix/fb/handle-net-err-closed-tcp-input

@andrewkroh andrewkroh requested review from a team as code owners February 4, 2022 00:10
@botelastic botelastic bot added the Team:Automation Label for the Observability productivity team label Feb 4, 2022
@andrewkroh andrewkroh force-pushed the bugfix/fb/handle-net-err-closed-tcp-input branch from 7a49dd3 to f288aed Compare February 4, 2022 00:13
@andrewkroh andrewkroh removed request for a team February 4, 2022 00:13
@andrewkroh andrewkroh removed the Team:Automation Label for the Observability productivity team label Feb 4, 2022
@andrewkroh andrewkroh requested a review from efd6 February 4, 2022 00:20
@andrewkroh andrewkroh merged commit 8c79b67 into elastic:main Feb 4, 2022
mergify bot pushed a commit that referenced this pull request Feb 4, 2022
…9712)

Stop accepting connections after tcp/unix socket is closed. This will suppress debug messages for net.ErrClosed.

    2021-12-22T13:49:04.151Z	INFO	[tcp]	streaming/listener.go:172	StoppingTCPserver	{"address": "0.0.0.0:7000"}
    2021-12-22T13:49:04.151Z	DEBUG	[tcp]	streaming/listener.go:129	Can not accept the connection	{"address": "0.0.0.0:7000", "error": "accept tcp [::]:7000: use of closed network connection"}

(cherry picked from commit 8c79b67)
andrewkroh added a commit that referenced this pull request Feb 4, 2022
…9712) (#30221)

Stop accepting connections after tcp/unix socket is closed. This will suppress debug messages for net.ErrClosed.

    2021-12-22T13:49:04.151Z	INFO	[tcp]	streaming/listener.go:172	StoppingTCPserver	{"address": "0.0.0.0:7000"}
    2021-12-22T13:49:04.151Z	DEBUG	[tcp]	streaming/listener.go:129	Can not accept the connection	{"address": "0.0.0.0:7000", "error": "accept tcp [::]:7000: use of closed network connection"}

(cherry picked from commit 8c79b67)

Co-authored-by: Andrew Kroh <andrew.kroh@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-v8.1.0 Automated backport with mergify bug Filebeat Filebeat Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants