MCPcopy
hub / github.com/wavetermdev/waveterm / handleRequestInternal

Method handleRequestInternal

pkg/wshutil/wshrpc.go:327–379  ·  view source on GitHub ↗
(req *RpcMessage, ingressLinkId baseds.LinkId, pprofCtx context.Context)

Source from the content-addressed store, hash-verified

325}
326
327func (w *WshRpc) handleRequestInternal(req *RpcMessage, ingressLinkId baseds.LinkId, pprofCtx context.Context) {
328 if req.Command == wshrpc.Command_EventRecv {
329 w.handleEventRecv(req)
330 return
331 }
332
333 var respHandler *RpcResponseHandler
334 timeoutMs := req.Timeout
335 if timeoutMs <= 0 {
336 timeoutMs = DefaultTimeoutMs
337 }
338 ctx, cancelFn := context.WithTimeout(context.Background(), time.Duration(timeoutMs)*time.Millisecond)
339 ctx = withWshRpcContext(ctx, w)
340 respHandler = &RpcResponseHandler{
341 w: w,
342 ctx: ctx,
343 reqId: req.ReqId,
344 command: req.Command,
345 commandData: req.Data,
346 source: req.Source,
347 ingressLinkId: ingressLinkId,
348 done: &atomic.Bool{},
349 canceled: &atomic.Bool{},
350 contextCancelFn: &atomic.Pointer[context.CancelFunc]{},
351 rpcCtx: w.GetRpcContext(),
352 }
353 respHandler.contextCancelFn.Store(&cancelFn)
354 respHandler.ctx = withRespHandler(ctx, respHandler)
355 if req.ReqId != "" {
356 w.registerResponseHandler(req.ReqId, respHandler)
357 }
358 isAsync := false
359 defer func() {
360 panicErr := panichandler.PanicHandler("handleRequest", recover())
361 if panicErr != nil {
362 respHandler.SendResponseError(panicErr)
363 }
364 if isAsync {
365 go func() {
366 defer func() {
367 panichandler.PanicHandler("handleRequest:finalize", recover())
368 }()
369 <-ctx.Done()
370 respHandler.Finalize()
371 }()
372 } else {
373 cancelFn()
374 respHandler.Finalize()
375 }
376 }()
377 handlerFn := serverImplAdapter(w.ServerImpl)
378 isAsync = !handlerFn(respHandler)
379}
380
381func (w *WshRpc) runServer() {
382 defer func() {

Callers 1

handleRequestMethod · 0.95

Calls 9

handleEventRecvMethod · 0.95
GetRpcContextMethod · 0.95
SendResponseErrorMethod · 0.95
FinalizeMethod · 0.95
PanicHandlerFunction · 0.92
withWshRpcContextFunction · 0.85
withRespHandlerFunction · 0.85
serverImplAdapterFunction · 0.85

Tested by

no test coverage detected