Skip to content

Commit

Permalink
Merge pull request #12702 from gabrielmougard/fix/dead-client-while-f…
Browse files Browse the repository at this point in the history
…ile-pull

Stop dead client connection from blocking instance snapshot / remove
  • Loading branch information
tomponline authored Jan 18, 2024
2 parents 4f9b618 + c8c7116 commit 431ad46
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 431ad46

Please sign in to comment.