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

socket_listener: clean up unix socket file on start & stop #2618

Merged
merged 1 commit into from
Apr 4, 2017
Merged

socket_listener: clean up unix socket file on start & stop #2618

merged 1 commit into from
Apr 4, 2017

Conversation

phemmer
Copy link
Contributor

@phemmer phemmer commented Apr 3, 2017

Includes 2 fixes for the socket_listener:

  1. On unix* sockets, unlink the file before start and after stop.
    This is the critical fix. When writing, I forgot about this step :-(
  2. Suppress "use of closed network connection" error on shutdown.
    On shutdown, we kill off the listener & reader goroutines by just shutting down the sockets they're using. But this was causing them to log the result as an error.

No change log entry since the plugin isn't in a released version yet.

Required for all PRs:

  • Sign CLA (if not already signed)

@@ -40,7 +39,6 @@ func TestSocketListener_udp(t *testing.T) {
}

func TestSocketListener_unix(t *testing.T) {
defer os.Remove("/tmp/telegraf_test.sock")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dunno how I forgot about the issue when I explicitly put the removal of the file in the test code...

sl := newSocketListener()
sl.ServiceAddress = "unixgram:///tmp/telegraf_test.sock"

acc := &testutil.Accumulator{}
err := sl.Start(acc)
require.NoError(t, err)
defer sl.Stop()
Copy link
Contributor Author

@phemmer phemmer Apr 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added so that the goroutines are shut down and the unix socket file removed. Otherwise they just get killed when go exits (finishes the tests), and the file is left around.

listener, err := net.Listen("unix", "/tmp/telegraf_test.sock")
require.NoError(t, err)
defer os.Remove("/tmp/telegraf_test.sock")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the defer needs to move upwards to ensure it is ran even if the require.NoError fails.

Copy link
Contributor Author

@phemmer phemmer Apr 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well if it errored, then the listen failed and the file wasn't created. Though it won't hurt to put it above.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah true

@danielnelson danielnelson merged commit f2805fd into influxdata:master Apr 4, 2017
calerogers pushed a commit to calerogers/telegraf that referenced this pull request Apr 5, 2017
vlamug pushed a commit to vlamug/telegraf that referenced this pull request May 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants