1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-08 05:57:03 +09:00

peerservice: do not dial under rlock

This commit is contained in:
Roman Khafizianov 2024-10-24 01:21:19 +02:00
parent c9bf97f31c
commit a3c6de7607
No known key found for this signature in database
GPG key ID: F07A7D55A2684852

View file

@ -4,6 +4,9 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"strings"
"sync"
"github.com/anyproto/any-sync/app" "github.com/anyproto/any-sync/app"
"github.com/anyproto/any-sync/app/logger" "github.com/anyproto/any-sync/app/logger"
"github.com/anyproto/any-sync/net/peer" "github.com/anyproto/any-sync/net/peer"
@ -14,8 +17,6 @@ import (
"github.com/anyproto/any-sync/net/transport/yamux" "github.com/anyproto/any-sync/net/transport/yamux"
"github.com/anyproto/any-sync/nodeconf" "github.com/anyproto/any-sync/nodeconf"
"go.uber.org/zap" "go.uber.org/zap"
"strings"
"sync"
) )
const CName = "net.peerservice" const CName = "net.peerservice"
@ -78,21 +79,20 @@ func (p *peerService) PreferQuic(prefer bool) {
} }
func (p *peerService) Dial(ctx context.Context, peerId string) (pr peer.Peer, err error) { func (p *peerService) Dial(ctx context.Context, peerId string) (pr peer.Peer, err error) {
p.mu.RLock()
defer p.mu.RUnlock()
addrs, err := p.getPeerAddrs(peerId)
if err != nil {
return
}
var mc transport.MultiConn
log.DebugCtx(ctx, "dial", zap.String("peerId", peerId), zap.Strings("addrs", addrs))
var schemes = yamuxPreferSchemes var schemes = yamuxPreferSchemes
p.mu.RLock()
if p.preferQuic { if p.preferQuic {
schemes = quicPreferSchemes schemes = quicPreferSchemes
} }
addrs, err := p.getPeerAddrs(peerId)
if err != nil {
p.mu.RUnlock()
return
}
p.mu.RUnlock()
var mc transport.MultiConn
log.DebugCtx(ctx, "dial", zap.String("peerId", peerId), zap.Strings("addrs", addrs))
err = ErrAddrsNotFound err = ErrAddrsNotFound
for _, sch := range schemes { for _, sch := range schemes {