Skip to content

Conversation

tcheeric
Copy link
Owner

Summary

  • Make WebSocketClientIF extend AutoCloseable and expose a close() method
  • Guard websocket session shutdowns and provide close() implementations in Standard and Spring clients
  • Switch handlers, usage sites, and tests to the new close() API and try-with-resources

Testing

  • mvn -q verify (fails: Could not find a valid Docker environment)

https://chatgpt.com/codex/tasks/task_b_689929b8f5048331bbde279ac9cf8e20

Copilot

This comment was marked as outdated.

…tandardWebSocketClient.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@tcheeric tcheeric requested a review from Copilot August 10, 2025 23:50
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements the AutoCloseable interface for WebSocket clients to enable automatic resource management with try-with-resources blocks, improving resource cleanup and preventing potential memory leaks.

  • Add AutoCloseable interface to WebSocketClientIF and provide a close() method to replace closeSocket()
  • Implement guarded session shutdown logic in StandardWebSocketClient to handle edge cases during close operations
  • Update all usage sites and tests to use try-with-resources pattern for automatic cleanup

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
WebSocketClientIF.java Extends AutoCloseable, adds close() method, deprecates closeSocket()
StandardWebSocketClient.java Implements robust close() with null/state checks, deprecates closeSocket()
SpringWebSocketClient.java Implements AutoCloseable, delegates to underlying client close()
WebSocketClientHandler.java Updates to use new close() API instead of closeSocket()
Test files Convert to try-with-resources pattern for automatic cleanup

@@ -111,7 +111,26 @@ public List<String> send(String json) throws IOException {
}

@Override
public void close() throws IOException {
if (clientSession.isOpen()) {
Copy link
Preview

Copilot AI Aug 10, 2025

Choose a reason for hiding this comment

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

This line appears to be unreachable code. Line 116 checks if clientSession is not null, but line 115 already calls isOpen() on clientSession without a null check, which would throw a NullPointerException if clientSession is null.

Suggested change
if (clientSession.isOpen()) {

Copilot uses AI. Check for mistakes.

…tandardWebSocketClient.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@tcheeric tcheeric merged commit 5a44fea into develop Aug 10, 2025
1 check passed
@tcheeric tcheeric deleted the codex/implement-autocloseable-for-websocketclients branch August 10, 2025 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant