Skip to content

Commit

Permalink
lxd/response: Watch for liveness of the TCP connection for single fil…
Browse files Browse the repository at this point in the history
…e response

Signed-off-by: Gabriel Mougard <[email protected]>
  • Loading branch information
gabrielmougard committed Jan 17, 2024
1 parent 97792f7 commit c8c7116
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lxd/response/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import (
"time"

"github.com/canonical/lxd/client"
"github.com/canonical/lxd/lxd/ucred"
"github.com/canonical/lxd/lxd/util"
"github.com/canonical/lxd/shared/api"
"github.com/canonical/lxd/shared/logger"
"github.com/canonical/lxd/shared/tcp"
)

var debug bool
Expand Down Expand Up @@ -401,6 +403,16 @@ func (r *fileResponse) Render(w http.ResponseWriter) error {

// For a single file, return it inline
if len(r.files) == 1 {
remoteConn := ucred.GetConnFromContext(r.req.Context())
remoteTCP, _ := tcp.ExtractConn(remoteConn)
if remoteTCP != nil {
// Apply TCP timeouts if remote connection is TCP (rather than Unix).
err := tcp.SetTimeouts(remoteTCP, 10*time.Second)
if err != nil {
return api.StatusErrorf(http.StatusInternalServerError, "Failed setting TCP timeouts on remote connection: %v", err)
}
}

var rs io.ReadSeeker
var mt time.Time
var sz int64
Expand Down

0 comments on commit c8c7116

Please sign in to comment.