Skip to content

SCTP teardown#552

Merged
shinyoshiaki merged 8 commits intodevelopfrom
ticket/d57c0b1a-bdea-41a4-8c0e-bc21983606bf
Feb 15, 2026
Merged

SCTP teardown#552
shinyoshiaki merged 8 commits intodevelopfrom
ticket/d57c0b1a-bdea-41a4-8c0e-bc21983606bf

Conversation

@shinyoshiaki
Copy link
Owner

This pull request focuses on making the SCTP teardown process robust, ensuring that after stopping, no asynchronous handles (timers, immediates) are left open and no timer rescheduling occurs. The changes introduce explicit stopping flags, guard all timer and input paths, and add regression tests to verify handle cleanup and prevent timer leaks. The implementation is careful to maintain backward compatibility and minimal impact on other components.

SCTP teardown and timer management improvements:

  • Added isStopping and isClosed flags to the SCTP class, and a unified isStopped getter to track and gate all teardown-related logic. All timer callbacks and rescheduling logic now check these flags to prevent timer regeneration after stopping. (packages/sctp/src/sctp.ts) [1] [2]
  • Updated all timer expiration, scheduling, and transmission methods (timer1Expired, timer2Expired, timer3Expired, timerReconfigHandleExpired, transmit, sendSack, scheduleSack, handleData, etc.) to return early if isStopped is true, ensuring no new timers or async operations are scheduled post-stop. (packages/sctp/src/sctp.ts) [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]
  • Modified stop() to clear all pending timer/immediate handles, set transport.onData = undefined, and ensure idempotence and no implicit transport closing, maintaining backward compatibility. (packages/sctp/src/sctp.ts) [1] [2]

Testing and regression checks:

  • Added a comprehensive regression test to api.test.ts verifying that after sending many messages and stopping, no timers are rescheduled, all handles are cleared, and transport.onData is undefined. (packages/sctp/tests/api.test.ts)
  • Introduced a new test script (open-handles-check.ts) and npm script (test:open-handles) for automated open handle detection after SCTP teardown, ensuring no timer leaks in real scenarios. (packages/sctp/tests/open-handles-check.ts, packages/sctp/package.json) [1] [2]

Documentation and planning:

  • Added a detailed task ticket outlining the motivation, technical approach, constraints, and completion criteria for robust SCTP teardown and open handle detection. (TICKET-ticket-d57c0b1a-bdea-41a4-8c0e-bc21983606bf.md)

【懸念事項】

完了条件の「mediasoup再現シナリオで Jest open handle 警告解消」はこのブランチ内で実証されておらず、追加テストも fake timers+privateメソッド直接呼び出し中心で実ハンドル検出(`--detectOpenHandles` 相当)を直接担保していません。

【改善提案】

- mediasoup の `test-werift-sctp.ts` 相当シナリオを real timer で実行する統合テストを追加

- 実行手順に `--detectOpenHandles`(Jest側)を明記して CI または検証ログを添付

- 必要なら `UdpTransport.close(): Promise<void>` の設計検討結果をチケットに追記

残りイテレーション回数: 0回
@shinyoshiaki shinyoshiaki merged commit 62a98f7 into develop Feb 15, 2026
1 check passed
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.

1 participant