mirror of
https://github.com/minio/minio.git
synced 2025-02-09 04:38:09 -05:00
Tweak one way stream ping (#19743)
Do not log errors on oneway streams when sending ping fails. Instead cancel the stream. This also makes sure pings are sent when blocked on sending responses. I will do a separate PR that includes this and adds pings to two-way streams as well as tests for pings.
This commit is contained in:
parent
0e59e50b39
commit
6d3e0c7db6
@ -331,6 +331,7 @@ func (m *muxClient) handleOneWayStream(respHandler chan<- Response, respServer <
|
|||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
sendResp:
|
||||||
select {
|
select {
|
||||||
case respHandler <- resp:
|
case respHandler <- resp:
|
||||||
m.respMu.Lock()
|
m.respMu.Lock()
|
||||||
@ -341,16 +342,47 @@ func (m *muxClient) handleOneWayStream(respHandler chan<- Response, respServer <
|
|||||||
case <-m.ctx.Done():
|
case <-m.ctx.Done():
|
||||||
// Client canceled. Don't block.
|
// Client canceled. Don't block.
|
||||||
// Next loop will catch it.
|
// Next loop will catch it.
|
||||||
}
|
|
||||||
case <-pingTimer:
|
case <-pingTimer:
|
||||||
if time.Since(time.Unix(atomic.LoadInt64(&m.LastPong), 0)) > clientPingInterval*2 {
|
if !m.doPing(respHandler) {
|
||||||
m.addErrorNonBlockingClose(respHandler, ErrDisconnected)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Send new ping.
|
goto sendResp
|
||||||
gridLogIf(m.ctx, m.send(message{Op: OpPing, MuxID: m.MuxID}))
|
}
|
||||||
|
case <-pingTimer:
|
||||||
|
if !m.doPing(respHandler) {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// doPing checks last ping time and sends another ping.
|
||||||
|
func (m *muxClient) doPing(respHandler chan<- Response) (ok bool) {
|
||||||
|
m.respMu.Lock()
|
||||||
|
if m.closed {
|
||||||
|
m.respMu.Unlock()
|
||||||
|
// Already closed. This is not an error state;
|
||||||
|
// we may just be delivering the last responses.
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only check ping when not closed.
|
||||||
|
if got := time.Since(time.Unix(atomic.LoadInt64(&m.LastPong), 0)); got > clientPingInterval*2 {
|
||||||
|
m.respMu.Unlock()
|
||||||
|
if debugPrint {
|
||||||
|
fmt.Printf("Mux %d: last pong %v ago, disconnecting\n", m.MuxID, got)
|
||||||
|
}
|
||||||
|
m.addErrorNonBlockingClose(respHandler, ErrDisconnected)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send new ping
|
||||||
|
err := m.sendLocked(message{Op: OpPing, MuxID: m.MuxID})
|
||||||
|
m.respMu.Unlock()
|
||||||
|
if err != nil {
|
||||||
|
m.addErrorNonBlockingClose(respHandler, err)
|
||||||
|
}
|
||||||
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// responseCh is the channel to that goes to the requester.
|
// responseCh is the channel to that goes to the requester.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user