CheckedContinuation never resumed in NetworkTransport send/receive on actor dealloc (Swift 6.3)

Open
#214 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
swift
Domain
networking

Research direction

Start by inspecting NetworkTransport.send(_:), sendHeartbeat(), and receiveData(), focusing on their NWConnection completion handlers and CheckedContinuation usage. Reproduce the deallocation scenario described in the issue, then verify that each in-flight operation completes rather than hanging and that every continuation is resumed exactly once. PR #213 is referenced as related work.

Written by the indexing model from the issue text.

Description

Bug

When NetworkTransport is deallocated while an async send(), sendHeartbeat(), or receiveData() operation is in-flight, the CheckedContinuation inside the NWConnection completion handler is never resumed — causing a permanent deadlock.

Root Cause

The .contentProcessed completion closures capture [weak self] but do not capture continuation directly. When self becomes nil in the completion handler, the guard let self else { return } exits without resuming the continuation.

This violates Swift's CheckedContinuation contract: a continuation must be resumed exactly once. Never resuming causes the caller to hang forever. In debug builds (Swift 6.3), this produces a runtime warning.

Affected Methods
  • NetworkTransport.send(_ message: Data).contentProcessed completion
  • NetworkTransport.sendHeartbeat().contentProcessed completion
  • NetworkTransport.receiveData()connection.receive completion (strong self capture inconsistency)
Reproduction
  1. Create a NetworkTransport connection
  2. Start a send() call
  3. Deallocate the transport before the NWConnection completion fires
  4. The caller hangs indefinitely
Environment
  • Swift 6.3 (also affects earlier versions, but Swift 6.3 strict concurrency makes it more visible)
  • Network framework (NWConnection)
Fix

Capture continuation directly in completion closures alongside [weak self], and resume with an error in the guard's else branch. See PR #213.

Dominant language
Swift
Stars
1.5k
Forks
243
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from modelcontextprotocol/swift-sdk

All issues in modelcontextprotocol/swift-sdk

Similar issues

More Swift issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.