Update message pool to include optional context deadline
This commit is contained in:
parent
c485baaadf
commit
a5e2bea04c
@ -53,9 +53,11 @@ func newMessagePool(peerManager peermanager.PeerManager, messageHandler MessageH
|
|||||||
|
|
||||||
func (s *messagePool) SendSync(ctx context.Context, peerId string, msg *spacesyncproto.ObjectSyncMessage) (reply *spacesyncproto.ObjectSyncMessage, err error) {
|
func (s *messagePool) SendSync(ctx context.Context, peerId string, msg *spacesyncproto.ObjectSyncMessage) (reply *spacesyncproto.ObjectSyncMessage, err error) {
|
||||||
s.updateLastUsage()
|
s.updateLastUsage()
|
||||||
|
if _, ok := ctx.Deadline(); !ok {
|
||||||
var cancel context.CancelFunc
|
var cancel context.CancelFunc
|
||||||
ctx, cancel = context.WithTimeout(ctx, time.Minute)
|
ctx, cancel = context.WithTimeout(ctx, time.Minute)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
}
|
||||||
newCounter := s.counter.Add(1)
|
newCounter := s.counter.Add(1)
|
||||||
msg.RequestId = genReplyKey(peerId, msg.ObjectId, newCounter)
|
msg.RequestId = genReplyKey(peerId, msg.ObjectId, newCounter)
|
||||||
log.InfoCtx(ctx, "mpool sendSync", zap.String("requestId", msg.RequestId))
|
log.InfoCtx(ctx, "mpool sendSync", zap.String("requestId", msg.RequestId))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user