Skip to content

fix: handle CancellationException in WebSocketTransport#663

Draft
devcrocod wants to merge 3 commits intomainfrom
devcrocod/websocket-transport-cancellation
Draft

fix: handle CancellationException in WebSocketTransport#663
devcrocod wants to merge 3 commits intomainfrom
devcrocod/websocket-transport-cancellation

Conversation

@devcrocod
Copy link
Copy Markdown
Contributor

closes #17

How Has This Been Tested?

integration tests

Breaking Changes

none

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Copilot AI review requested due to automatic review settings April 1, 2026 12:47
Copy link
Copy Markdown
Contributor

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 addresses flaky WebSocket transport shutdown behavior by treating coroutine cancellation as a normal close signal instead of an error, and re-enables the previously ignored WebSocket integration tests with a safety timeout to prevent CI hangs.

Changes:

  • Suppress _onError callbacks when a WebSocket session completes with CancellationException, invoking the close callback instead.
  • Re-enable WebSocketTransportTest cases and migrate them to JUnit Jupiter annotations.
  • Add a class-level JUnit timeout to reduce CI flakiness/hangs.

Reviewed changes

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

File Description
kotlin-sdk-core/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/shared/WebSocketMcpTransport.kt Treats CancellationException as a normal shutdown path in the session completion handler.
integration-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/WebSocketTransportTest.kt Re-enables WebSocket transport integration tests and adds a JUnit timeout to stabilize CI execution.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@devcrocod devcrocod force-pushed the devcrocod/websocket-transport-cancellation branch from cbc9c57 to c4fa2df Compare April 10, 2026 16:27
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...rotocol/kotlin/sdk/shared/WebSocketMcpTransport.kt 0.00% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@devcrocod devcrocod requested a review from e5l April 10, 2026 16:44
@devcrocod devcrocod marked this pull request as ready for review April 10, 2026 16:44
Copilot AI review requested due to automatic review settings April 10, 2026 16:44
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings April 29, 2026 10:48
@devcrocod devcrocod marked this pull request as draft April 29, 2026 10:51
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

import io.ktor.websocket.readText
import io.modelcontextprotocol.kotlin.sdk.types.JSONRPCMessage
import io.modelcontextprotocol.kotlin.sdk.types.McpJson
import kotlinx.coroutines.CancellationException
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

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

This file now imports both kotlinx.coroutines.CancellationException and kotlin.coroutines.cancellation.CancellationException, which will either be ambiguous at compile time or lead to inconsistent type checks (e.g., the catch (e: CancellationException) and it !is CancellationException checks). Remove one import and consistently use the project-standard kotlin.coroutines.cancellation.CancellationException (as used in other core transport code).

Suggested change
import kotlinx.coroutines.CancellationException

Copilot uses AI. Check for mistakes.
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.

Investigate WebSocketTransportTest.should start then close cleanly failing only with GH action

5 participants