Skip to content

Refine connection exception for internal control flow#47

Merged
cclilshy merged 7 commits intomainfrom
cursor/refine-connection-exception-for-internal-control-flow-d087
Sep 10, 2025
Merged

Refine connection exception for internal control flow#47
cclilshy merged 7 commits intomainfrom
cursor/refine-connection-exception-for-internal-control-flow-d087

Conversation

@cclilshy
Copy link
Copy Markdown
Member

Redefine ConnectionException as an internal control-flow exception and introduce event-driven lifecycle callbacks (onClose, onReadableEnd, onWritableEnd) to provide clear connection state management and robust error handling.

The previous ConnectionException was ambiguously used for both internal control flow and application-level errors, leading to potential deadlocks in the event loop and unclear user interaction. This refactoring ensures the reactor can reliably terminate connections on fatal I/O errors while empowering users with explicit, event-based notifications for connection lifecycle events, including half-close scenarios.


Open in Cursor Open in Web

Co-authored-by: jingnigg <jingnigg@gmail.com>
@cursor
Copy link
Copy Markdown

cursor Bot commented Aug 31, 2025

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

cursor[bot]

This comment was marked as outdated.

@cursor
Copy link
Copy Markdown

cursor Bot commented Aug 31, 2025

I refactored stream-related exceptions, primarily replacing ConnectionException with TransportException for broader transport errors and introducing TransportTimeoutException. I also refined stream closing logic and fixed a CloseEvent constructor issue, improving overall stream robustness and error handling.

  • I replaced most usages of Ripple\Stream\Exception\ConnectionException with Ripple\Stream\Exception\TransportException across src/Proc/Session.php, src/Socket.php, src/Stream.php, src/Worker/Worker.php, src/Worker/WorkerProcess.php, and tests/UnixTest.php for more general transport error handling.
  • I introduced Ripple\Stream\Exception\TransportTimeoutException in src/Socket.php for specific SSL handshake timeouts, providing clearer error differentiation.
  • I modified src/Stream.php to improve emitCloseEvent by extracting the ConnectionAbortReason from ConnectionException when available, ensuring accurate close event details.
  • I fixed the src/Stream/CloseEvent.php constructor to explicitly assign the timestamp property, resolving a potential issue with readonly properties and the null coalescing assignment operator.
  • I adjusted Stream::write in src/Stream.php to only suspend coroutines waiting for buffer clearance if there is actual data in the buffer, preventing unnecessary suspensions.
  • I added a new test file test_fix.php to validate the CloseEvent constructor fix and the internal usage of ConnectionException.

Open in Cursor Open in Web

Learn more about Cursor Agents

@cclilshy cclilshy marked this pull request as ready for review August 31, 2025 16:10
cursor[bot]

This comment was marked as outdated.

@cclilshy
Copy link
Copy Markdown
Member Author

@cursor review

cursor[bot]

This comment was marked as outdated.

@cloudtay cloudtay deleted a comment from cursor Bot Sep 10, 2025
@cloudtay cloudtay deleted a comment from cursor Bot Sep 10, 2025
Comment thread composer.json
@cclilshy cclilshy merged commit dd56fa4 into main Sep 10, 2025
44 of 49 checks passed
@cclilshy cclilshy deleted the cursor/refine-connection-exception-for-internal-control-flow-d087 branch September 25, 2025 11:20
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.

2 participants