Skip to content

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!

}
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!

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