invoices: refactor invoice subscriptions to avoid blocking
This commit fixes a potential blocking when notifying invoice updates. When a new subscription client is created followed by an immediate cancel, it's likely the client will be removed from the registry's map(noop) and then added to its map again. This subscription will then be kept in registry until lnd is restarted. Another more serious issue is when multiple subscriptions are made for the same invoice, when the above case happens, other subscriptions may never send invoice updates because a previous client has a stopped notification queue that blocks following notifications.
This commit is contained in:
2 files changed
+98
-105
No files matched your search
@@ -244,6 +244,8 @@ func (s *Server) SubscribeSingleInvoice(req *SubscribeSingleInvoiceRequest,
|
||||
}
|
||||
defer invoiceClient.Cancel()
|
||||
|
||||
log.Debugf("Created new single invoice(pay_hash=%v) subscription", hash)
|
||||
|
||||
for {
|
||||
select {
|
||||
case newInvoice := <-invoiceClient.Updates:
|
||||
@@ -265,7 +267,9 @@ func (s *Server) SubscribeSingleInvoice(req *SubscribeSingleInvoiceRequest,
|
||||
}
|
||||
|
||||
case <-updateStream.Context().Done():
|
||||
return updateStream.Context().Err()
|
||||
return fmt.Errorf("subscription for "+
|
||||
"invoice(pay_hash=%v): %w", hash,
|
||||
updateStream.Context().Err())
|
||||
|
||||
case <-s.quit:
|
||||
return nil
|
||||
|
||||
Reference in new issue
Block a user