Skip to content

Commit

Permalink
fix concurrent map write error
Browse files Browse the repository at this point in the history
  • Loading branch information
zkokelj committed Oct 27, 2023
1 parent f744ae2 commit a6c8ba3
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tools/walletextension/subscriptions/subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"sync"
"time"

"github.com/go-kit/kit/transport/http/jsonrpc"
Expand All @@ -20,6 +21,7 @@ import (
type SubscriptionManager struct {
subscriptionMappings map[string][]string
logger gethlog.Logger
mu sync.Mutex
}

func New(logger gethlog.Logger) *SubscriptionManager {
Expand Down Expand Up @@ -100,6 +102,10 @@ func checkIfUserConnIsClosedAndUnsubscribe(userConn userconn.UserConn, subscript
}

func (sm *SubscriptionManager) UpdateSubscriptionMapping(userSubscriptionID string, obscuroNodeSubscriptionID string) {
// Ensure there is no concurrent map writes
sm.mu.Lock()
defer sm.mu.Unlock()

existingUserIDs, exists := sm.subscriptionMappings[userSubscriptionID]

if !exists {
Expand Down

0 comments on commit a6c8ba3

Please sign in to comment.