fix: make Start() idempotent when box is already running#496
Closed
nieyy wants to merge 1 commit into
Closed
Conversation
c48475d to
9352394
Compare
Member
|
Hi @nieyy. Please use English only |
9352394 to
1971647
Compare
## Problem Start() returns ErrInvalidState when the box was already started by Create(), even though the box is actually running. Affects all users following the standard pattern of calling create() then start(). ## Root Cause Create() was updated to auto-start the box, but Start() was not made idempotent. When the box is already Running, Start() returns ErrInvalidState, which propagates as an error. ## Change Extract startIdempotent() in the runner client: when ErrInvalidState is received, call Info() to confirm the box is actually Running before suppressing the error. All other states (Stopping, etc.) propagate the error unchanged. Unconditionally suppressing ErrInvalidState would be wrong — the error code also covers Stopping/Paused states that are genuine failures. Also adds api_id() to BoxBackend for REST API ID handling and fixes CLI linker issue on Linux. ## Verification ```bash cd apps/runner go test -tags boxlite_dev ./pkg/boxlite/ -run TestStartIdempotent -v ``` All 4 tests pass.
1971647 to
b5830b1
Compare
Author
|
will open another pr later |
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.
问题
box.start()在 box 已由Create()自动启动的情况下返回 HTTP 404,但 box 实际上正在运行。影响所有按标准示例调用
create()+start()的用户。
根因
Create()加入了自动启动逻辑,但Start()没有做幂等处理。当 box处于 Running 状态时,
bx.Start()在状态转换窗口内触发ErrInvalidState,runner 将其直接作为错误返回,HTTP 层映射成 404。
改动
提取
startIdempotent()函数:收到ErrInvalidState时先调用bx.Info()确认 box 是否真的在 Running,只有确认后才静默忽略,其他状态(Stopping 等)的错误原样透传。
直接吞掉所有
ErrInvalidState是错的——该错误码还覆盖 Stopping /Unknown 等真正需要报错的状态。
验证
4 个测试全部 PASS。