Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can you please rework this fix to use try-with-resources, so there is no need of an explicit 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.
We only want the serverChannel closed if the BindException occurs. Otherwise it needs to be returned to the caller in an open state. I don't believe try-with-resources is what we want here but let me know if I misunderstood.
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.
@sbordet try-with-resources doesn't work in this case as we use the socket in the successful case... actually probably should null out the field... just in case....
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.
Actually no fields were set, but there was one already in a try-with-resources, so backed the change out of that one.
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.
Looks like the serverChannel is within the method scope so nothing to null out. I looked at the caller scope or otherwise to see if there was a better place to adjust the close (such as a try with resources). And I'm not seeing that. For the specific issue observed the change as I have it closes that problem. If this is part of a larger concern I'm not sure I follow. Do you need any change from the patch as-is?
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.
Re: using try-with-resources: doh :)
@gregw #5802 is the same fix? @joewitt can you use
IO.close()
instead? Also, I think we want to catch everything that may possibly be throws afterServerSocketChannel.open()
, so I would widen thetry
scope.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.
Incorporating this change within #5802.