Repository navigation
refactor: 会话资源收敛为内部 Session 对象 + 拆除分段(#68 PR-2) - #95
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
关闭范围:#68 的 PR-2(建议范围第一条"内部 Session 对象集中持有"+ 第三条"评估异步停止与先中止 I/O 再等待的顺序"的保守落地)。基于 PR-1(#94)的行为基线与守门。
会话对象化
会话五元组(
_sessionCts/_pipe/_receiveTask/_decodeTask/_sendWorkerTask/_sessionStartedAt)收敛为不可变的内部Session类(id/epoch/socket/Pipe/CTS/三任务/建立时刻),发布到_session前在_sessionGate内完成装配:ReceiveLoopAsync(session)、SendWorkerAsync(session)、SendRawAsync(…, socket))——不再读"当前值"字段,直连迁移(双循环竞速)中新旧会话互不干扰;拆除只关本会话的 socket。_socket字段降级为"当前值"镜像:诊断(RemoteIpAddress)与建立交接用;I/O 一律走会话自己的 socket。拆除分段(已知限制①收口)
StopSessionCore拆为两段:DetachSession(锁内,无等待):结算时长指标 → 取消令牌 → 唤醒解码读取 → 先关闭本会话 socket。关 socket 前置于等待任务:netfx 上取消令牌无法中止已提交的接收,只有关 socket 能立即解锁阻塞 I/O("先中止 I/O 再等待")——netfx 拆除收敛显著加快。WaitAndDisposeSession(锁外):有界等待三任务 ≤2s、释放 CTS。会话锁内不再有任何等待:高并发重连/停机不再在_sessionGate上排队(PR-1 调试期观察到的RapidServerInitiatedReconnects慢收敛敏感即源于此)。停机/重连的总阻塞时长与公共 API 的同步/异步行为不变(#68 约束)。
验证
StateOwnershipBaselineTests终态不变量改为断言_session为 null;SendQueueContinuationTests经_session.Tasks取 worker(嵌套类型反射须从开放泛型定义构造后闭合)。DESIGN
资源所有权表改为"会话对象"行(装配/快速中止/锁外收尾)、
_socket镜像语义行;锁清单标注会话锁内无等待;已知限制更新:①收口后剩余"停机仍同步等待(锁外 ≤2s,公共 API 行为保持)",②僵尸接受帧不在 accept 后复查代次( tolerated,统一状态转换入口是剩余结构收敛项)。