mirror of
https://github.com/lxc/incus
synced 2026-08-02 05:26:46 +00:00
incusd/response: Abort piped exports that fail mid-stream
The PipeResponse mechanism would always send an early header, then process the piped data. That's done to avoid hitting a header submission timeout. The problem with that is that a failure is now being interpreted as success by the client as there is no way to go back and change the HTTP status code. Instead, use a bit of a hack by aborting the connection entirely. This is done through a scary panic() call which is intercepted by the Go HTTP server and will cause the underlying connection to be terminated without affecting the rest of the daemon. Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
This commit is contained in:
parent
89c7b49297
commit
4ff2b98385
@ -758,7 +758,14 @@ func (r *pipeResponse) Render(w http.ResponseWriter) error {
|
||||
}
|
||||
|
||||
_, err := util.SafeCopy(w, r.reader)
|
||||
return err
|
||||
if err != nil {
|
||||
// It's too late to send a clean error back to the client, so
|
||||
// instead use the Go HTTP ErrAbortHandler logic to terminate the
|
||||
// connection. This does not cause the daemon itself to panic.
|
||||
panic(http.ErrAbortHandler)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// String returns a quick description of the response.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user