aboutsummaryrefslogtreecommitdiff
path: root/http_server.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-12-22 03:07:29 +0700
committerShulhan <ms@kilabit.info>2023-12-22 03:09:46 +0700
commiteb5868459b9053df3499417653e4ca432907afb4 (patch)
treed0cafbdeef9da157f2e39c02f7ebb08f3792ccc5 /http_server.go
parent65c66728904a8a26fa8593cfe6a7d39e45c0ef1f (diff)
downloadawwan-eb5868459b9053df3499417653e4ca432907afb4.tar.xz
all: delete the execution response and context cancellation on finished
Once the ExecResponse EndAt is not empty or event queue has been closed, clear the map that store the execution response and context cancellation to minimize resources usage.
Diffstat (limited to 'http_server.go')
-rw-r--r--http_server.go18
1 files changed, 11 insertions, 7 deletions
diff --git a/http_server.go b/http_server.go
index 2a01332..8a61ce8 100644
--- a/http_server.go
+++ b/http_server.go
@@ -845,20 +845,21 @@ func (httpd *httpServer) ExecuteTail(sseconn *libhttp.SSEConn) {
}
execRes.mtxOutput.Unlock()
+ var (
+ ok = true
+
+ ev sseclient.Event
+ evid int64
+ )
+
if len(execRes.EndAt) != 0 {
// The execution has been completed.
sseconn.WriteEvent(`end`, execRes.EndAt, nil)
- return
+ goto out
}
// And wait for the rest...
- var (
- ok = true
-
- ev sseclient.Event
- evid int64
- )
for {
ev, ok = <-execRes.eventq
if !ok {
@@ -877,4 +878,7 @@ func (httpd *httpServer) ExecuteTail(sseconn *libhttp.SSEConn) {
}
sseconn.WriteEvent(ev.Type, ev.Data, &ev.ID)
}
+out:
+ delete(httpd.idExecRes, execID)
+ delete(httpd.idContextCancel, execID)
}