Skip to content

Commit 5efa91c

Browse files
committed
Mobile: add mutext to protect mc var
1 parent d58e391 commit 5efa91c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

mobile/mobile.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ var (
9494
// mMutex should always be used to guard the m map
9595
mMutex sync.RWMutex
9696

97+
// mcMutex should be used to guard the mc variable
98+
mcMutex sync.RWMutex
99+
97100
registry = make(map[string]func(context.Context,
98101
*grpc.ClientConn, string, func(string, error)))
99102

@@ -174,16 +177,18 @@ func ConnectServer(nameSpace string, mailboxServer string, isDevServer bool,
174177
}
175178

176179
mMutex.Lock()
177-
defer mMutex.Unlock()
178-
179180
mc, ok := m[nameSpace]
181+
mMutex.Unlock()
180182
if !ok {
181183
return fmt.Errorf("unknown namespace: %s", nameSpace)
182184
}
183185

184186
// Since the connection function is blocking, we need to spin it off
185187
// in another goroutine here. See https://pkg.go.dev/syscall/js#FuncOf.
186188
go func() {
189+
mcMutex.Lock()
190+
defer mcMutex.Unlock()
191+
187192
statusChecker, lndConnect, err := core.MailboxRPCConnection(
188193
mailboxServer, pairingPhrase, localPriv, remotePub,
189194
func(key *btcec.PublicKey) error {

0 commit comments

Comments
 (0)