Long RPCs ignore cancellation mid-operation; a done context only withholds the answer

未关闭
#2,337 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
38/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
go
领域
api, backend

调研方向

Start with the existing context checks in internal/frontend/grpc/runs.go and the handler locations listed in the issue, then trace the long parse, convert, query, render, and document operations. Add bounded cancellation checks through those paths and update the contract comment in client/opensysml/inprocess.go. Add deterministic counting-context tests for mid-loop cancellation and deadlines; done means each listed RPC returns the context status promptly and concurrent calls remain unaffected.

由索引模型根据 Issue 内容生成。

描述

Disclaimer, this issue was detected and written by an AI

Summary

Most engine calls honour a context: RunRuns, RunSweep, CheckBehavior,
CompareResults, Explore*, ImportData and SelfCheck notice ctx.Err() and
stop (or return it). The long parse/convert/query/render paths do not.
client/opensysml/inprocess.go:258 states the current contract:

The engine runs a call to completion; a done context withholds whatever it
produced, answer or error, as the wire does.

So a caller deadline returns DEADLINE_EXCEEDED while the engine keeps parsing,
converting or querying. On a memory-constrained host a handful of timed-out
requests stack full CPU and memory cost: the timeouts make the overload worse,
not better.

Where the checks already are

  • internal/frontend/grpc/runs.go:173,261 (RunRuns)
  • internal/frontend/grpc/sweep.go:143 (RunSweep)
  • internal/frontend/grpc/check.go:186 (CheckBehavior)
  • internal/frontend/grpc/compare.go:196 (CompareResults)
  • internal/frontend/grpc/explore.go:45 (Explore*)
  • internal/frontend/grpc/importdata.go:49 (ImportData)
  • internal/frontend/grpc/selfcheck.go:56 (SelfCheck)

These return ctx.Err(); connect maps context.Canceled/DeadlineExceeded, and
the in-process answer maps them through contextStatus (inprocess.go:271).

Where they are missing (the work)

Add the same pattern — check at phase boundaries and every N elements/documents,
then return ctx.Err() — to:

RPC File Where to check
ParseFile internal/frontend/grpc/service.go:824 before/after the parse
ParseSources service.go:857 per document in the set, and between analysis and the response build
Convert export.go:28 before preparation, between export.PrepareModel, toGraph, graph build and serialization; per document in convertModelOfDocuments (export.go:564)
Migrate export.go:189 per migrated document/phase
Query query.go:99 in candidates/collect and when building rows, every ~1024 elements
RenderView render_view.go before and after the render
RenderDocument documents.go (render path) before and after the render
ExportGraphs export_graphs.go before and after the export
RunDocumentQuery docquery.go per row
InstancePaths instancepaths.go per node during the walk
ElementProperties element_properties.go per document/element
Instantiate objects.go per behavior/object

Notes:

  • Check cheaply: if err := ctx.Err(); err != nil { return nil, err } at the top
    of each document/row and every few hundred elements; do not call ctx.Err()
    per property.
  • Return the context error unchanged, so the wire code is CANCELLED /
    DEADLINE_EXCEEDED on both transports. Do not turn it into an INVALID_ARGUMENT
    or a 200 with error.
  • After this, update the inprocess.go:258 comment: the engine checks the
    context where the work is long, and a done context returns the status.
  • ParseSources is the biggest win in-process: a 572 KB/13-document project
    takes ~2 s cold, and an abandoned tree read or export currently keeps it
    running.

Tests

Service tests (internal/frontend/grpc), calling the handlers directly like
affected_test.go does:

  • A counting context that answers nil for N Err() calls and
    context.Canceled afterwards. ParseSources and Convert over a large model
    return CodeCanceled (not a result), and return before the uncancelled call
    would have finished. Pin the exact behaviour: with N below the first check the
    call is untouched; with N inside the document loop it stops after the current
    document.
  • The same for Query over a large scope.
  • context.DeadlineExceeded yields CodeDeadlineExceeded, not CodeCanceled.
  • A concurrent call on another model still completes (no shared cancellation).
  • An in-process client test (client/opensysml) drives ParseDocuments with the
    counting context and asserts StatusError{Code: CodeCanceled} and that the
    partial model is not returned.

Avoid wall-clock-only tests: under a loaded 4-core box a 2 s parse is not a stable
oracle. The counting context makes the stop point deterministic.

Acceptance

  • Every long RPC above stops within a bounded number of elements/documents of
    a cancellation and returns CANCELLED/DEADLINE_EXCEEDED.
  • A pre-cancelled request still returns immediately (unchanged).
  • Concurrent calls are unaffected.
  • The answer comment and any docs that say "runs to completion" are updated.
  • Tests cover both cancellation and deadline, at a mid-loop check point.
主要语言
Go
星标
59
派生
20
平均合并
10 小时 23 分钟
30 天内合并 PR
897

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Open-MBEE/OpenSysML 的其他 Issue

查看 Open-MBEE/OpenSysML 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。