Skip to content

Commit 867d345

Browse files
committed
mobile: ConnectServer: use mutex more conservatively
1 parent b412095 commit 867d345

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

mobile/mobile.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,16 @@ func ConnectServer(nameSpace string, mailboxServer string, isDevServer bool,
198198
return
199199
}
200200

201-
mc.mutex.Lock()
202-
defer mc.mutex.Unlock()
203-
204201
statusChecker, lndConnect, err := core.MailboxRPCConnection(
205202
mailboxServer, pairingPhrase, localPriv, remotePub,
206203
func(key *btcec.PublicKey) error {
204+
mc.mutex.Lock()
205+
defer mc.mutex.Unlock()
206+
207207
mc.remoteKeyReceiveCallback.SendResult(
208-
hex.EncodeToString(key.SerializeCompressed()),
208+
hex.EncodeToString(
209+
key.SerializeCompressed(),
210+
),
209211
)
210212

211213
return nil
@@ -228,23 +230,34 @@ func ConnectServer(nameSpace string, mailboxServer string, isDevServer bool,
228230
"macaroon: %v", err)
229231
}
230232

231-
mc.mac = mac
233+
mc.mutex.Lock()
234+
defer mc.mutex.Unlock()
232235

236+
mc.mac = mac
233237
mc.authDataCallback.SendResult(string(data))
234238

235239
return nil
236240
},
237241
)
238242
if err != nil {
239243
log.Errorf("Error running wasm client: %v", err)
244+
return
240245
}
241246

247+
mc.mutex.Lock()
242248
mc.statusChecker = statusChecker
243-
mc.lndConn, err = lndConnect()
249+
mc.mutex.Unlock()
250+
251+
lndConn, err := lndConnect()
244252
if err != nil {
245253
log.Errorf("Error running wasm client: %v", err)
254+
return
246255
}
247256

257+
mc.mutex.Lock()
258+
mc.lndConn = lndConn
259+
mc.mutex.Unlock()
260+
248261
log.Debugf("Mobile client connected to RPC")
249262
}()
250263

0 commit comments

Comments
 (0)