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
activation: close files after creating listeners #250
Conversation
Travis failure seems to be unrelated to this change. |
However, it should be noted that I don't see any downside to not close the file descriptor. Whatever we do, systemd will keep its own file descriptor, therefore, it's not possible for a user to completely close the associated file description. |
Existing examples seem to hint at the fact that received FDs could be re-used multiple times, however #215 (comment) seems to state that the original FD is closed/gone after this change. I need to double-check systemd side for the expected semantics, and golang land for Just for reference, what is the root-cause for this PR? An actual bug/leakage reported somewhere? |
I was just looking at the open issues and pull requests and thought that closing the file descriptor was a good idea. But as I say in my last comment, I don't see any downside of leaving the file descriptor unclosed because closing it has no effect because systemd is keeping its own open. |
@vincentbernat I think #252 tackled this transient test failure, can you please rebase both your PRs on current master? |
b2904e2
to
41c34bd
Compare
Done. But after a day, I think this one could just be closed. |
Thanks, tests seem greener, but I'm re-triggering travis just to be sure. I'm leaving this open as a reminder to myself to have a proper look into the File-closing part. I guess the same questions applies to #251, so in the worst case it will help in reviewing that. |
So, I spent a bit of time looking into this today and these are my comments at the end of the investigation.
As such, I would propose to re-purpose this PR to do the following:
@vincentbernat how does this sound to you? |
If there is a risk of the original fd to be closed by the GC after the first File instance, I would be more in favor of closing them and not letting the user reuse them. Otherwise, we expose them to heisenbugs they may or may not source here. Otherwise, we dup them ourselves before putting them in a File. |
In which case we probably want to remove the
That would be another option. I'm not a great fan of dup-ing several time the fds we receive, though. |
If we keep this as is, we already get your proposed behavior since the |
You are technically correct, sorry if I didn't go into details enough. Even though golang garbage-collects Files (and fds) on its own all the time, as far as I know it is idiomatic to manually close them as soon as it is known that they are not needed anymore (I think primarily to avoid ulimit issues). This was the missing context around my comment on conditionally doing that. |
activation/listeners.go
Outdated
@@ -32,6 +32,7 @@ func Listeners(unsetEnv bool) ([]net.Listener, error) { | |||
for i, f := range files { | |||
if pc, err := net.FileListener(f); err == nil { | |||
listeners[i] = pc | |||
f.Close() |
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 would better be:
if unsetEnv {
f.Close()
}
activation/packetconns.go
Outdated
@@ -31,6 +31,7 @@ func PacketConns(unsetEnv bool) ([]net.PacketConn, error) { | |||
for i, f := range files { | |||
if pc, err := net.FilePacketConn(f); err == nil { | |||
conns[i] = pc | |||
f.Close() |
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.
Same as above, this would be conditional on unsetEnv
.
Ping. I've opened a discussion on Go |
This is an adaptation of coreos#215 to ensure tests don't fail and extend the behaviour to PacketConns(). A bit of test coverage is lost, but just testing if variable environments are not unset in the simple case doesn't seem worth adding more code. Fix coreos#215
41c34bd
to
4e7a0c4
Compare
OK, PR updated. I have restored the tests as they work as is now. |
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.
LGTM
So, the I'm more inclined to just remove the |
I agree with you. |
This is an adaptation of #215 to ensure tests don't fail and extend
the behaviour to PacketConns(). A bit of test coverage is lost, but
just testing if variable environments are not unset in the simple case
doesn't seem worth adding more code.
Fix #215