diff --git a/internal/grid/debugmsg_string.go b/internal/grid/debugmsg_string.go index 4c8676e39..a84f811b5 100644 --- a/internal/grid/debugmsg_string.go +++ b/internal/grid/debugmsg_string.go @@ -15,11 +15,12 @@ func _() { _ = x[debugSetConnPingDuration-4] _ = x[debugSetClientPingDuration-5] _ = x[debugAddToDeadline-6] + _ = x[debugIsOutgoingClosed-7] } -const _debugMsg_name = "debugShutdowndebugKillInbounddebugKillOutbounddebugWaitForExitdebugSetConnPingDurationdebugSetClientPingDurationdebugAddToDeadline" +const _debugMsg_name = "debugShutdowndebugKillInbounddebugKillOutbounddebugWaitForExitdebugSetConnPingDurationdebugSetClientPingDurationdebugAddToDeadlinedebugIsOutgoingClosed" -var _debugMsg_index = [...]uint8{0, 13, 29, 46, 62, 86, 112, 130} +var _debugMsg_index = [...]uint8{0, 13, 29, 46, 62, 86, 112, 130, 151} func (i debugMsg) String() string { if i < 0 || i >= debugMsg(len(_debugMsg_index)-1) { diff --git a/internal/grid/muxclient.go b/internal/grid/muxclient.go index 1b380a341..2078dc19a 100644 --- a/internal/grid/muxclient.go +++ b/internal/grid/muxclient.go @@ -91,7 +91,13 @@ func (m *muxClient) roundtrip(h HandlerID, req []byte) ([]byte, error) { msg.Flags |= FlagSubroute } ch := make(chan Response, 1) + m.respMu.Lock() + if m.closed { + m.respMu.Unlock() + return nil, ErrDisconnected + } m.respWait = ch + m.respMu.Unlock() ctx := m.ctx // Add deadline if none. @@ -101,8 +107,8 @@ func (m *muxClient) roundtrip(h HandlerID, req []byte) ([]byte, error) { ctx, cancel = context.WithTimeout(ctx, defaultSingleRequestTimeout) defer cancel() } - // Send... (no need for lock yet) - if err := m.sendLocked(msg); err != nil { + // Send request + if err := m.send(msg); err != nil { return nil, err } if debugReqs { @@ -215,7 +221,13 @@ func (m *muxClient) RequestStream(h HandlerID, payload []byte, requests chan []b return nil, errors.New("RequestStream: responses channel is nil") } m.init = true + m.respMu.Lock() + if m.closed { + m.respMu.Unlock() + return nil, ErrDisconnected + } m.respWait = responses // Route directly to output. + m.respMu.Unlock() // Try to grab an initial block. m.singleResp = false