-
Notifications
You must be signed in to change notification settings - Fork 102
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
uds-stream: close unused sockets #243
Conversation
We need to make sure we close the socket file descriptors before forgetting them otherwise we leak fds.
@@ -136,9 +136,11 @@ private void connect() throws IOException { | |||
} | |||
if (!delegate.connect(address)) { | |||
if (connectionTimeout > 0 && System.nanoTime() > deadline) { | |||
delegate.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.
Would it make sense to do this with a try/finally
block? AFAICS setOption
can throw too, and we'd leak then too.
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.
not sure how you would use a finally here 🤔 but I tried a try
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.
You are right, catch
makes more sense of course.
if (connectionTimeout > 0 && System.nanoTime() > deadline) { | ||
delegate.close(); | ||
throw new IOException("Connection timed out"); | ||
try { |
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.
Would it make sense for this block to cover setOption for connectionTimeout above?
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.
yes
throw new IOException("Connection timed out"); | ||
} | ||
if (!delegate.finishConnect()) { | ||
closeSafe(delegate); |
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.
Is this call redundant with the catch
block?
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.
yes
@@ -1,5 +1,6 @@ | |||
package com.timgroup.statsd; | |||
|
|||
import java.net.SocketOption; |
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 appears to be unused.
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.
removed
/merge |
🚂 MergeQueue Pull request added to the queue. This build is going to start soon! (estimated merge in less than 0s) Use |
We need to make sure we close the socket
file descriptors before forgetting them otherwise
we leak fds.