mirror of
https://github.com/lnbits/lnbits.git
synced 2025-03-18 05:41:54 +01:00
fix: NWC mark and remove subs before sending close request (#2870)
* mark and remove subscription even if close event fails to send * catch CLOSE subscription exceptions * format
This commit is contained in:
parent
7e27b2c6f0
commit
0574837950
@ -401,16 +401,17 @@ class NWCConnection:
|
||||
for subscription in self.subscriptions.values():
|
||||
if subscription["sub_id"] == sub_id:
|
||||
sub_to_close = subscription
|
||||
# send CLOSE event to the relay if the subscription
|
||||
# is not already closed and sendEvent is True
|
||||
if not subscription["closed"] and send_event:
|
||||
await self._send(["CLOSE", sub_id])
|
||||
# mark as closed
|
||||
subscription["closed"] = True
|
||||
break
|
||||
# remove the subscription from the list
|
||||
if sub_to_close:
|
||||
self.subscriptions.pop(sub_to_close["event_id"], None)
|
||||
if not sub_to_close["closed"]:
|
||||
sub_to_close["closed"] = True
|
||||
if send_event:
|
||||
try:
|
||||
await self._send(["CLOSE", sub_id])
|
||||
except Exception as e:
|
||||
logger.error("Error closing subscription: " + str(e))
|
||||
return sub_to_close
|
||||
|
||||
async def _close_subscription_by_eventid(
|
||||
@ -430,12 +431,13 @@ class NWCConnection:
|
||||
# find and remove the subscription
|
||||
subscription = self.subscriptions.pop(event_id, None)
|
||||
if subscription:
|
||||
# send CLOSE event to the relay if the subscription
|
||||
# is not already closed and sendEvent is True
|
||||
if not subscription["closed"] and send_event:
|
||||
await self._send(["CLOSE", subscription["sub_id"]])
|
||||
# mark as closed
|
||||
subscription["closed"] = True
|
||||
if not subscription["closed"]:
|
||||
subscription["closed"] = True
|
||||
if send_event:
|
||||
try:
|
||||
await self._send(["CLOSE", subscription["sub_id"]])
|
||||
except Exception as e:
|
||||
logger.error("Error closing subscription: " + str(e))
|
||||
return subscription
|
||||
|
||||
async def _wait_for_connection(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user