diff --git a/control/controlclient/direct.go b/control/controlclient/direct.go index 593aa463d..46f759fc6 100644 --- a/control/controlclient/direct.go +++ b/control/controlclient/direct.go @@ -1121,18 +1121,22 @@ func (c *Direct) sendMapRequest(ctx context.Context, isStreaming bool, nu Netmap return nil } - if c.streamingMapSession != nil { + if isStreaming && c.streamingMapSession != nil { panic("mapSession is already set") } sess := newMapSession(persist.PrivateNodeKey(), nu, c.controlKnobs) - c.streamingMapSession = sess - defer func() { - sess.Close() - c.mu.Lock() - c.streamingMapSession = nil - c.mu.Unlock() - }() + if isStreaming { + c.streamingMapSession = sess + defer func() { + sess.Close() + c.mu.Lock() + c.streamingMapSession = nil + c.mu.Unlock() + }() + } else { + defer sess.Close() + } sess.cancel = cancel sess.logf = c.logf sess.vlogf = vlogf