diff --git a/package-lock.json b/package-lock.json index 177ffc1c8b..e436dc9511 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "waveterm", - "version": "0.12.1", + "version": "0.12.2-beta.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "waveterm", - "version": "0.12.1", + "version": "0.12.2-beta.1", "hasInstallScript": true, "license": "Apache-2.0", "workspaces": [ diff --git a/pkg/wshutil/wshrpc.go b/pkg/wshutil/wshrpc.go index ff6bec23e8..3b70ff4db5 100644 --- a/pkg/wshutil/wshrpc.go +++ b/pkg/wshutil/wshrpc.go @@ -269,25 +269,26 @@ func (w *WshRpc) cancelRequest(reqId string) { } func (w *WshRpc) handleRequest(req *RpcMessage) { - pprof.Do(context.Background(), pprof.Labels("rpc", req.Command), func(ctx context.Context) { - w.handleRequestInternal(req) + pprof.Do(context.Background(), pprof.Labels("rpc", req.Command), func(pprofCtx context.Context) { + w.handleRequestInternal(req, pprofCtx) }) } -func (w *WshRpc) handleRequestInternal(req *RpcMessage) { - // events first +func (w *WshRpc) handleEventRecv(req *RpcMessage) { + if req.Data == nil { + return + } + var waveEvent wps.WaveEvent + err := utilfn.ReUnmarshal(&waveEvent, req.Data) + if err != nil { + return + } + w.EventListener.RecvEvent(&waveEvent) +} + +func (w *WshRpc) handleRequestInternal(req *RpcMessage, pprofCtx context.Context) { if req.Command == wshrpc.Command_EventRecv { - if req.Data == nil { - // invalid - return - } - var waveEvent wps.WaveEvent - err := utilfn.ReUnmarshal(&waveEvent, req.Data) - if err != nil { - // invalid - return - } - w.EventListener.RecvEvent(&waveEvent) + w.handleEventRecv(req) return } @@ -670,12 +671,15 @@ func (handler *RpcResponseHandler) close() { // if async, caller must call finalize func (handler *RpcResponseHandler) Finalize() { + // Always unregister the handler from the map, even if already done + if handler.reqId != "" { + handler.w.unregisterResponseHandler(handler.reqId) + } if handler.reqId == "" || handler.done.Load() { return } handler.SendResponse(nil, true) handler.close() - handler.w.unregisterResponseHandler(handler.reqId) } func (handler *RpcResponseHandler) IsDone() bool {