Skip to content

Commit 6f9f324

Browse files
accounts: process requests before stopping service
Ensure that we don't stop the service while we're processing a request. This is especially important to ensure that we don't stop the service exactly after a user has made an rpc call to send a payment we can't know the payment hash for prior to the actual payment being sent (i.e. Keysend or SendToRoute). This is because if we stop the service after the send request has been sent to lnd, but before TrackPayment has been called, we won't be able to track the payment and debit the account.
1 parent 666f19c commit 6f9f324

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

accounts/service.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,18 @@ func (s *InterceptorService) Start(lightningClient lndclient.LightningClient,
214214

215215
// Stop shuts down the account service.
216216
func (s *InterceptorService) Stop() error {
217+
// We need to lock the request mutex to ensure that we don't stop the
218+
// service while we're processing a request.
219+
// This is especially important to ensure that we don't stop the service
220+
// exactly after a user has made an rpc call to send a payment we can't
221+
// know the payment hash for prior to the actual payment being sent
222+
// (i.e. Keysend or SendToRoute). This is because if we stop the service
223+
// after the send request has been sent to lnd, but before TrackPayment
224+
// has been called, we won't be able to track the payment and debit the
225+
// account.
226+
s.requestMtx.Lock()
227+
defer s.requestMtx.Unlock()
228+
217229
s.contextCancel()
218230
close(s.quit)
219231

0 commit comments

Comments
 (0)