Skip to content

[Bug] Object storage write waits after its context is canceled #26273

Closed

Description

@Ariznawlll

Summary

objectStorageSemaphore does not observe the caller context while waiting for a slot in Write.

CopyObject and Delete use acquireContext, but Write uses the unconditional acquire path. The same waiting pattern is also used by Exists, Read, Stat, and WriteMultipartParallel.

Reproduction

On main commit c8e443bf8610b2af4333ad943ba2075485b16cf8:

  1. Create an objectStorageSemaphore with capacity 1 and occupy its only slot.
  2. Create and cancel a context.
  3. Call Write with that canceled context.

The call remains waiting for the semaphore slot instead of returning context.Canceled. The isolated test repeated this result 3/3 times with a 100 ms upper bound per run.

Expected behavior

Once the caller context has ended, a queued file operation should return that context result without waiting for another operation to release the slot, and it should not call the upstream storage.

Actual behavior

The queued Write call remains blocked until the slot is released. Therefore an operation that has already been canceled can still wait behind a long-running storage operation.

Suggested direction

Use the context-aware acquisition path consistently for operations that accept a context, while retaining the existing release behavior after a slot is acquired.

Activity

  1. added this to the MO-202607 milestone on Jul 28, 2026
  2. added
    kind/bug
    on Jul 28, 2026
  3. added theissue type on Jul 28, 2026
  4. added
    severity/s0
    and removed on Jul 31, 2026
  5. LeftHandCold commented on Aug 3, 2026

    @LeftHandCold
    Collaborator

    fixed

  6. Ariznawlll commented on Aug 7, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:ab49099c0f487255df131f45c3aecf4a4650fed7
    • 部署方式:Go UT;go test -race -count=3 ./pkg/fileservice
    • 测试日期:2026-08-07

    原问题验证

    验证 object-storage semaphore 被占用时,等待写入的 context cancellation 会立即生效,不再继续无意义等待。

    Happy Path 覆盖

    1. CopyObject 正常执行正确。
    2. semaphore 串行化行为正确。
    3. 取消等待路径的各操作在 race detector 下连续 3 次稳定通过。

    Unhappy Path 覆盖

    1. 等待 semaphore 时取消 context:delete、exists、list、read、stat、write、parallel multipart write 均观察到取消并返回。
    2. copy 与 delete 的等待取消分别覆盖;未发现 race,也未出现 goroutine 卡住。

    白盒验证

    执行 TestObjectStorageSemaphoreCopyObject、TestObjectStorageSemaphoreDeleteObservesContextWhileWaiting、TestObjectStorageSemaphoreOperationsObserveContextWhileWaiting、TestObjectStorageSemaphoreSerializes,使用 -race -count=3。

    回归测试

    已运行 pkg/fileservice 既有 UT;未新增代码或回归文件。

    测试证据

    • 全部目标 UT:3/3 PASS。
    • -race 未报告数据竞争。

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions