Skip to content

Commit 6c1c6a1

Browse files
drwtsn95dennis-tra
authored andcommitted
Make neighbors routing tables access mutual exclusive
1 parent 5e53b57 commit 6c1c6a1

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

db/pg.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ type PostgresClient struct {
132132
peerMappings map[peer.ID]int
133133

134134
// ... TODO
135-
routingTables map[peer.ID]struct {
135+
routingTablesMu sync.Mutex
136+
routingTables map[peer.ID]struct {
136137
neighbors []peer.ID
137138
errorBits uint16
138139
}
@@ -640,13 +641,15 @@ func (c *PostgresClient) InsertVisit(ctx context.Context, args *VisitArgs) error
640641
wg.Wait()
641642

642643
if c.cfg.PersistNeighbors && (len(args.Neighbors) > 0 || args.ErrorBits != 0) {
644+
c.routingTablesMu.Lock()
643645
c.routingTables[args.PeerID] = struct {
644646
neighbors []peer.ID
645647
errorBits uint16
646648
}{
647649
neighbors: args.Neighbors,
648650
errorBits: args.ErrorBits,
649651
}
652+
c.routingTablesMu.Unlock()
650653
}
651654

652655
var crawlID *int
@@ -933,6 +936,8 @@ func (c *PostgresClient) FetchUnresolvedMultiAddresses(ctx context.Context, limi
933936

934937
// Flush .
935938
func (c *PostgresClient) Flush(ctx context.Context) error {
939+
c.routingTablesMu.Lock()
940+
defer c.routingTablesMu.Unlock()
936941
if len(c.routingTables) == 0 || !c.cfg.PersistNeighbors {
937942
return nil
938943
}

0 commit comments

Comments
 (0)