fix(server): return nil from Run() retry path instead of misleading error#311
Closed
wc4440222 wants to merge 1 commit into
Closed
fix(server): return nil from Run() retry path instead of misleading error#311wc4440222 wants to merge 1 commit into
wc4440222 wants to merge 1 commit into
Conversation
Contributor
Code Review Result — lgtm ✅1. Copyright Check
2. Go Style
3. Abstract Interface Check
4. Architecture Check
5. Concurrency Safety
6. Security
Verdict: lgtm — Clean fix for misleading error return with improved observability. |
…rror
When retry is enabled, Run() launches the server in a background
goroutine but previously returned fmt.Errorf("init err") which
misled callers into thinking the server failed to start. Return nil
instead since the server is actually starting in the background.
Also log the retry configuration at startup for visibility.
Signed-off-by: wc4440222 <[email protected]>
wc4440222
force-pushed
the
fix/server-run-retry-error
branch
from
July 7, 2026 08:06
7ec3891 to
f83ba97
Compare
Contributor
Author
|
@hao022 @huhong-web Hi, this PR has been lgtm'd for 9 days. Could you please take a look and merge when convenient? Thanks! |
Member
|
@wc4440222 你好感谢贡献代码。当前已经重构了server 模块。建议删除run 这个函数,实现和huatuo-apiserver 相同的调用方式。 推荐修复删除旧的 Run 和 Option,让 huatuo-bamai 也使用: Start → Done/Wait → Shutdown 具体调整:
重试逻辑应类似: for {
err := httpServer.Start(addr)
if err == nil {
return httpServer, nil
}
timer := time.NewTimer(backoffDuration)
select {
case <-ctx.Done():
timer.Stop()
return nil, fmt.Errorf("start HTTP server: %w", ctx.Err())
case <-timer.C:
}
} |
Contributor
Author
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.
What does this PR do?
Fixes a misleading error return in
internal/server/server.goRun()method.Problem
When retry is enabled (
RetryMaxTime > 0 && RetryInterval > 0),Run()launches the server in a background goroutine with exponential backoff but always returnsfmt.Errorf("init err")to the caller. This misleads callers into thinking the server failed to start when it is actually running.The caller already uses
_ = s.Run(...)which masks the error, so this bug has gone unnoticed.Fix
Return
nilfrom the retry path since the server IS starting. Also log the retry configuration at startup for visibility.Testing
go build ./internal/server/— compiles ✅go test ./internal/server/ -count=1— all 21 existing tests pass ✅Checklist
Signed-off-by: wc4440222 [email protected]