gitea-ci: cerrar conexiones

This commit is contained in:
Cat /dev/Nulo 2023-01-29 22:03:18 -03:00
parent 2f27ecda45
commit 0320f9f88f
2 changed files with 13 additions and 4 deletions

View file

@ -27,7 +27,7 @@ func (l logWebsocket) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
defer c.Close(websocket.StatusInternalError, "the sky is falling")
ch := make(chan *[]byte)
ch := make(chan *[]byte, 1000)
err = run.addWriter(conn{ch: ch})
if err != nil {
log.Println("addWriter", err)
@ -38,7 +38,10 @@ func (l logWebsocket) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if payload == nil {
break
} else {
c.Write(context.Background(), websocket.MessageBinary, *payload)
err = c.Write(context.Background(), websocket.MessageBinary, *payload)
if err != nil {
return
}
}
}
c.Close(websocket.StatusNormalClosure, "")

View file

@ -23,6 +23,7 @@ import (
type run struct {
mutex sync.Mutex
finished bool
previous []byte
writers []io.WriteCloser
}
@ -45,13 +46,18 @@ func (r *run) addWriter(w io.WriteCloser) (err error) {
r.mutex.Lock()
defer r.mutex.Unlock()
go w.Write(slices.Clone(r.previous))
r.writers = append(r.writers, w)
w.Write(slices.Clone(r.previous))
if r.finished {
w.Close()
} else {
r.writers = append(r.writers, w)
}
return
}
func (r *run) finishRun() {
r.mutex.Lock()
defer r.mutex.Unlock()
r.finished = true
for _, c := range r.writers {
c.Close()
}