(msg RpcMessage)
| 845 | } |
| 846 | |
| 847 | func (w *WshRpc) sendRespWithBlockMessage(msg RpcMessage) { |
| 848 | respCh, rd := w.getResponseCh(msg.ResId) |
| 849 | if respCh == nil { |
| 850 | return |
| 851 | } |
| 852 | select { |
| 853 | case respCh <- &msg: |
| 854 | // normal case, message got sent, just return! |
| 855 | return |
| 856 | default: |
| 857 | // channel is full, we would block... |
| 858 | } |
| 859 | // log the fact that we're blocking |
| 860 | _, noLog := blockingExpMap.Get(msg.ResId) |
| 861 | if !noLog { |
| 862 | log.Printf("[rpc:%s] blocking on response command:%s route:%s resid:%s\n", w.DebugName, rd.Command, rd.Route, msg.ResId) |
| 863 | blockingExpMap.Set(msg.ResId, true, time.Now().Add(time.Second)) |
| 864 | } |
| 865 | ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) |
| 866 | defer cancel() |
| 867 | select { |
| 868 | case respCh <- &msg: |
| 869 | // message got sent, just return! |
| 870 | return |
| 871 | case <-ctx.Done(): |
| 872 | } |
| 873 | log.Printf("[rpc:%s] failed to clear response channel (waited 1s), will fail RPC command:%s route:%s resid:%s\n", w.DebugName, rd.Command, rd.Route, msg.ResId) |
| 874 | w.unregisterRpc(msg.ResId, nil) // we don't pass an error because the channel is full, it won't work anyway... |
| 875 | } |
no test coverage detected