Merge branch 'master' into 9998-no-count-items-available
[arvados.git] / services / ws / handler.go
index 8d8edcac3417543037bb5397b112d6ca82d51788..72291900fac52c4192f4db971e29bd736be5c189 100644 (file)
@@ -31,6 +31,7 @@ func (h *handler) Handle(ws wsConn, eventSource eventSource, newSession func(wsC
        h.setupOnce.Do(h.setup)
 
        ctx, cancel := context.WithCancel(ws.Request().Context())
+       defer cancel()
        log := logger(ctx)
 
        incoming := eventSource.NewSink()
@@ -52,6 +53,8 @@ func (h *handler) Handle(ws wsConn, eventSource eventSource, newSession func(wsC
                return
        }
 
+       // Receive websocket frames from the client and pass them to
+       // sess.Receive().
        go func() {
                buf := make([]byte, 2<<20)
                for {
@@ -83,6 +86,9 @@ func (h *handler) Handle(ws wsConn, eventSource eventSource, newSession func(wsC
                }
        }()
 
+       // Take items from the outgoing queue, serialize them using
+       // sess.EventMessage() as needed, and send them to the client
+       // as websocket frames.
        go func() {
                for {
                        var ok bool
@@ -192,7 +198,7 @@ func (h *handler) Handle(ws wsConn, eventSource eventSource, newSession func(wsC
        return
 }
 
-func (h *handler) Status() interface{} {
+func (h *handler) DebugStatus() interface{} {
        h.mtx.Lock()
        defer h.mtx.Unlock()