mirror of
https://github.com/mudler/LocalAI.git
synced 2026-05-25 01:02:05 -04:00
fix(distributed): set node header before first byte on streaming error path
In the chat.go error-from-worker branch the call to applyNodeIDHeader came after fmt.Fprintf had already written to the response writer. Go's http.ResponseWriter commits headers on the first Write, so the X-LocalAI-Node header was silently dropped on streaming error responses. Move the call before each Fprintf so the header is set on both the marshal-error and the normal-error paths. The non-streaming chat path and the completion error path were already correctly ordered. Assisted-by: Claude:claude-opus-4-7[1m] Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
@@ -449,12 +449,13 @@ func ChatEndpoint(cl *config.ModelConfigLoader, ml *model.ModelLoader, evaluator
|
||||
respData, marshalErr := json.Marshal(errorResp)
|
||||
if marshalErr != nil {
|
||||
xlog.Error("Failed to marshal error response", "error", marshalErr)
|
||||
applyNodeIDHeader()
|
||||
fmt.Fprintf(c.Response().Writer, "data: {\"error\":{\"message\":\"Internal error\",\"type\":\"server_error\"}}\n\n")
|
||||
} else {
|
||||
applyNodeIDHeader()
|
||||
fmt.Fprintf(c.Response().Writer, "data: %s\n\n", respData)
|
||||
}
|
||||
fmt.Fprintf(c.Response().Writer, "data: [DONE]\n\n")
|
||||
applyNodeIDHeader()
|
||||
c.Response().Flush()
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user