Skip to content

v2-server: 观察者关闭时 stream Next 返回 context.Canceled 而非 execution unavailable - #355

Merged
EricWvi merged 1 commit into
ora-space:mainfrom
TannyXie:fix/1013-runtime-observer-close-error
Nov 10, 2026
Merged

EricWvi merged 1 commit into
ora-space:mainfrom
TannyXie:fix/1013-runtime-observer-close-error

Conversation

@TannyXie

Copy link
Copy Markdown
Contributor

Refs ora-space/circus#1039

v2,不涉及 specs。

背景

TestRuntimeObserverCloseAndAdmissionContextDoNotCancel(v2-server/internal/executionruntime)偶发失败:

runtime_test.go:403: closed observer=execution unavailable

本地复现: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),没有把观察者关闭当作执行不可用来推进状态。

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.
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.

2 participants