mirror of
https://github.com/stashapp/stash.git
synced 2025-12-06 08:26:00 +01:00
Prevent hang when deleting while streaming (#3169)
This commit is contained in:
parent
7bb35b2b09
commit
aafbba7d77
1 changed files with 16 additions and 1 deletions
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/stashapp/stash/internal/manager/config"
|
"github.com/stashapp/stash/internal/manager/config"
|
||||||
"github.com/stashapp/stash/internal/static"
|
"github.com/stashapp/stash/internal/static"
|
||||||
|
|
@ -46,7 +47,21 @@ func (c *StreamRequestContext) Cancel() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warnf("unable to write end of stream: %v", err)
|
logger.Warnf("unable to write end of stream: %v", err)
|
||||||
}
|
}
|
||||||
_ = bw.Flush()
|
|
||||||
|
// flush the buffer, but don't wait indefinitely
|
||||||
|
timeout := make(chan struct{}, 1)
|
||||||
|
go func() {
|
||||||
|
_ = bw.Flush()
|
||||||
|
close(timeout)
|
||||||
|
}()
|
||||||
|
|
||||||
|
const waitTime = time.Second
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-timeout:
|
||||||
|
case <-time.After(waitTime):
|
||||||
|
logger.Warnf("unable to flush buffer - closing connection")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
conn.Close()
|
conn.Close()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue