Repository navigation
v2-server: 观察者关闭时 stream Next 返回 context.Canceled 而非 execution unavailable - #355
Merged
EricWvi merged 1 commit intoNov 10, 2026
Merged
Conversation
When Close cancels the stream context mid-query, the wrapped database error lost context.Canceled and publicError classified it as execution unavailable. asNextError prefers the query context's own cancellation so a closed observer returns context.Canceled.
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.
Refs ora-space/circus#1039
v2,不涉及 specs。
背景
TestRuntimeObserverCloseAndAdmissionContextDoNotCancel(v2-server/internal/executionruntime)偶发失败:本地复现:
go test -race -run TestRuntimeObserverCloseAndAdmissionContextDoNotCancel -count=200在 200 次里失败 4 次,报错与 CI 一致。根因
stream.Next用context.AfterFunc(st.ctx, cancel)在Close()时取消内部查询 context。若取消发生在数据库查询进行中,pgx 返回的包裹错误不保留context.Canceled,publicError将其归为execution.ErrUnavailable。已关闭的观察者因此拿到"执行不可用",而不是context.Canceled。修复
新增
asNextError:任何内部查询出错时,先看查询 context 是否已被取消(无论来自Close()还是调用方取消),已取消则返回该取消错误,否则走原publicError归类。ReadExecutionEvents、ReadSession、终态复查三处错误返回统一走这条路径。验收
-count=200失败 4 次;修复后:-count=500全部通过,internal/executionruntime全包-race通过。Next错误的消费方已核对(见运行 issue #1039),没有把观察者关闭当作执行不可用来推进状态。