gitea-ci: cerrar conexiones
This commit is contained in:
parent
2f27ecda45
commit
0320f9f88f
2 changed files with 13 additions and 4 deletions
|
@ -27,7 +27,7 @@ func (l logWebsocket) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
defer c.Close(websocket.StatusInternalError, "the sky is falling")
|
defer c.Close(websocket.StatusInternalError, "the sky is falling")
|
||||||
|
|
||||||
ch := make(chan *[]byte)
|
ch := make(chan *[]byte, 1000)
|
||||||
err = run.addWriter(conn{ch: ch})
|
err = run.addWriter(conn{ch: ch})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("addWriter", err)
|
log.Println("addWriter", err)
|
||||||
|
@ -38,7 +38,10 @@ func (l logWebsocket) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
if payload == nil {
|
if payload == nil {
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
c.Write(context.Background(), websocket.MessageBinary, *payload)
|
err = c.Write(context.Background(), websocket.MessageBinary, *payload)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.Close(websocket.StatusNormalClosure, "")
|
c.Close(websocket.StatusNormalClosure, "")
|
||||||
|
|
|
@ -23,6 +23,7 @@ import (
|
||||||
|
|
||||||
type run struct {
|
type run struct {
|
||||||
mutex sync.Mutex
|
mutex sync.Mutex
|
||||||
|
finished bool
|
||||||
previous []byte
|
previous []byte
|
||||||
writers []io.WriteCloser
|
writers []io.WriteCloser
|
||||||
}
|
}
|
||||||
|
@ -45,13 +46,18 @@ func (r *run) addWriter(w io.WriteCloser) (err error) {
|
||||||
r.mutex.Lock()
|
r.mutex.Lock()
|
||||||
defer r.mutex.Unlock()
|
defer r.mutex.Unlock()
|
||||||
|
|
||||||
go w.Write(slices.Clone(r.previous))
|
w.Write(slices.Clone(r.previous))
|
||||||
r.writers = append(r.writers, w)
|
if r.finished {
|
||||||
|
w.Close()
|
||||||
|
} else {
|
||||||
|
r.writers = append(r.writers, w)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
func (r *run) finishRun() {
|
func (r *run) finishRun() {
|
||||||
r.mutex.Lock()
|
r.mutex.Lock()
|
||||||
defer r.mutex.Unlock()
|
defer r.mutex.Unlock()
|
||||||
|
r.finished = true
|
||||||
for _, c := range r.writers {
|
for _, c := range r.writers {
|
||||||
c.Close()
|
c.Close()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue