Skip to content

GH-9694: Remove duplicate SocketChannel initialization #9696

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

Merged
merged 2 commits into from
Dec 6, 2024

Conversation

anthologia
Copy link
Contributor

Fixes: #9694
Issue link: #9694

  • Remove duplicate socketChannel initialization
  • Properly close the SocketChannel when connection fails
  • Prevents socket resource leakage during connection retries

@pivotal-cla
Copy link

@anthologia Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-cla
Copy link

@anthologia Thank you for signing the Contributor License Agreement!

@@ -113,6 +115,11 @@ protected TcpConnectionSupport buildNewConnection() {
return wrappedConnection;
}
catch (IOException e) {
try {
socketChannel.close();
Copy link
Member

Choose a reason for hiding this comment

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

Don't we need to check if socketChannel != null first?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah right, I missed the null check. Thanks for catching that!

@@ -113,6 +115,11 @@ protected TcpConnectionSupport buildNewConnection() {
return wrappedConnection;
}
catch (IOException e) {
try {
socketChannel.close();
} catch (IOException e2) {
Copy link
Member

Choose a reason for hiding this comment

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

Our code style is to have catch on a new line.
You can run locally ./gradlew :spring-integration-ip:check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checked the style guide and fixed it accordingly. Thanks for the feedback :)

Fixes: spring-projects#9694
Issue link: spring-projects#9694

- Add null check before closing socketChannel in catch block
- Prevents potential NullPointerException during error handling
@artembilan artembilan merged commit 7427d4e into spring-projects:main Dec 6, 2024
3 checks passed
@artembilan
Copy link
Member

@anthologia ,
thank you for contribution; looking forward for more!

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.

Close SocketChannel in TcpNioClientConnectionFactory.buildNewConnection()
3 participants