[BanyanDB] Data race and nil-pointer panic: measure write during standalone shutdown after segment close

未关闭
#14,285 0 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 1 天内回复

@hanahmily 已经在做这个了。

开始于 2026年12月1日。

  • #1510 来自 @hanahmily —— 未关闭

评估

这个 Issue 还没有评估数据。

描述

bug
Search before asking
  • I had searched in the issues and found no similar issues.
Apache SkyWalking Component

BanyanDB (apache/skywalking-banyandb)

What happened

During shutdown of a standalone node, a measure write that is still in flight hits a segment whose series index was already closed. The race detector reports a data race, and the write batch panics with a nil pointer dereference:

  • Write side: measureService.Write → writeSession.Finish → sealLocked starts a write-batch goroutine → publishOnce → localBatchPublisher.Close → bus.Publish → measure.(*writeCallback).Rev → dps.segment.IndexDB().Insert(...) (banyand/measure/write_standalone.go:566).
  • Close side: schemaRepo.Close → group.close → database.Close → segmentController.close → segment.closeResourcesLocked, which sets s.index = nil (banyand/internal/storage/segment.go:357).

Root cause: oklog/run interrupts units one at a time in registration order ([email protected]/group.go:47). In pkg/cmdsetup/standalone.go, measureSvc (and the other storage services) are registered before grpcServer, so the storage is closed while the liaison gRPC server can still accept writes and run write batches. The write holds a segment reference, but database.Close closes the segment regardless.

Observed in CI as TestStandaloneActiveSeries (test/integration/standalone/active_series) failing with race detected during execution of test, even though all specs passed. It fired at teardown. It hit apache/skywalking-banyandb#1508 twice in a row (Integration Standalone – Remainder, America/Los_Angeles), although that PR touches only trace/sidx code. It did not reproduce in 3 local runs on main or on the PR branch, so it depends on timing.

What you expected to happen

Shutdown should stop accepting writes before closing storage, and in-flight writes should either complete or fail with an error. No data race and no panic.

How to reproduce

Timing-dependent. Run TZ=America/Los_Angeles go test -race ./test/integration/standalone/active_series/ repeatedly on CI runners. The race fires when a measure write batch is in flight while the node shuts down.

Anything else

Possible fixes, which can be combined:

  1. Stop the gRPC and HTTP servers before the storage services on shutdown, e.g. register them earlier or add an explicit shutdown phase, so in-flight write streams drain before schemaRepo.Close. Check the data node and liaison command setups for the same ordering.
  2. Make segment.IndexDB() / segment close respect outstanding references, or make the write path return an error on a closed segment instead of panicking.
Are you willing to submit a pull request to fix on your own?
  • Yes I am willing to submit a pull request!
Code of Conduct
主要语言
Java
星标
25k
派生
6.6k
平均合并
10 小时 45 分钟
30 天内合并 PR
49

环境准备

从这里开始

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

apache/skywalking 的其他 Issue

查看 apache/skywalking 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

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