fix(devops): use errEvt payload when sending error SSE event#786
Open
SKDG042 wants to merge 1 commit intocloudwego:mainfrom
Open
fix(devops): use errEvt payload when sending error SSE event#786SKDG042 wants to merge 1 commit intocloudwego:mainfrom
SKDG042 wants to merge 1 commit intocloudwego:mainfrom
Conversation
Contributor
Author
|
devops\internal\apihandler\debug.go:line140 这边貌似有点问题 debugID, stateCh, errCh, err := service.DebugSVC.DebugRun(ctx, m, rs.Input)
if err != nil {
log.Errorf("DebugRun err: %v", err)
return
}
sseStreamResponseChan := make(chan SSEResponse, 50)
wg := sync.WaitGroup{}
wg.Add(1)
safego.Go(ctx, func() {
defer wg.Done()
for {
select {
case <-ctx.Done():
return
case state, ok := <-stateCh:
if !ok {
evt := types.DebugRunFinishEVT(debugID)
sseStreamResponseChan <- NewStreamResponse(string(evt.Type), string(evt.JsonBytes()))
return
}
evt := types.DebugRunDataEVT(debugID, state)
if err != nil {
errEvt := types.DebugRunErrEVT(debugID, err.Error())
sseStreamResponseChan <- NewStreamResponse(string(errEvt.Type), string(errEvt.JsonBytes()))
return
}
sseStreamResponseChan <- NewStreamResponse(string(evt.Type), string(evt.JsonBytes()))
}
}
})
safego.Go(ctx, func() {
defer close(sseStreamResponseChan)
wg.Wait()
for e := range errCh {
evt := types.DebugRunErrEVT(debugID, e.Error())
sseStreamResponseChan <- NewStreamResponse(string(evt.Type), string(evt.JsonBytes()))
}
})当 if err != nil {
errEvt := types.DebugRunErrEVT(debugID, err.Error())
sseStreamResponseChan <- NewStreamResponse(string(errEvt.Type), string(errEvt.JsonBytes()))
return
}这一段错误处理永远不会触发, 所以这个bug一直没发现( |
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 type of PR is this?
fix
Check the PR title.
(Optional) Translate the PR title into Chinese.
发送错误 SSE 事件时使用 errEvt 的 payload
(Optional) More detailed description for this PR(en: English/zh: Chinese).
en:
In
devops/internal/apihandler/debug.go:165, when constructing the SSE response for the error branch, the event type is correctly taken fromerrEvt.Typebut the payload is mistakenly taken fromevt.JsonBytes()(the data event constructed one line earlier) instead oferrEvt.JsonBytes(). As a result, the frontend receives an SSE message whoseevent:claimserrorbut whosedata:body is actually a regular data event JSON, so the real error string (err.Error()) is silently dropped and the error reporting path becomes unusable.Before
After
This aligns with the other error-sending site in the same file (line 178), where both the type and the payload come from the same event variable.
zh(optional):
devops/internal/apihandler/debug.go:165在错误分支构造 SSE 响应时,事件类型正确地使用 errEvt.Type,但数据体却错误地取自 evt.JsonBytes(),而不是应该使用的 errEvt.JsonBytes()。这导致前端收到一条 event: error 但 data却是普通数据事件 JSON 的不一致消息,真实错误信息 err.Error() 被静默丢弃, 该修改与同文件第 178 行的另一处错误上报(类型与 payload 同源于一个事件变量)保持一致。(Optional) Which issue(s) this PR fixes:
(optional) The PR that updates user documentation: