mirror of
https://github.com/lnbits/lnbits.git
synced 2025-03-28 18:52:00 +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():
|
for subscription in self.subscriptions.values():
|
||||||
if subscription["sub_id"] == sub_id:
|
if subscription["sub_id"] == sub_id:
|
||||||
sub_to_close = subscription
|
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
|
break
|
||||||
# remove the subscription from the list
|
# remove the subscription from the list
|
||||||
if sub_to_close:
|
if sub_to_close:
|
||||||
self.subscriptions.pop(sub_to_close["event_id"], None)
|
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
|
return sub_to_close
|
||||||
|
|
||||||
async def _close_subscription_by_eventid(
|
async def _close_subscription_by_eventid(
|
||||||
@ -430,12 +431,13 @@ class NWCConnection:
|
|||||||
# find and remove the subscription
|
# find and remove the subscription
|
||||||
subscription = self.subscriptions.pop(event_id, None)
|
subscription = self.subscriptions.pop(event_id, None)
|
||||||
if subscription:
|
if subscription:
|
||||||
# send CLOSE event to the relay if the subscription
|
if not subscription["closed"]:
|
||||||
# is not already closed and sendEvent is True
|
subscription["closed"] = True
|
||||||
if not subscription["closed"] and send_event:
|
if send_event:
|
||||||
await self._send(["CLOSE", subscription["sub_id"]])
|
try:
|
||||||
# mark as closed
|
await self._send(["CLOSE", subscription["sub_id"]])
|
||||||
subscription["closed"] = True
|
except Exception as e:
|
||||||
|
logger.error("Error closing subscription: " + str(e))
|
||||||
return subscription
|
return subscription
|
||||||
|
|
||||||
async def _wait_for_connection(self):
|
async def _wait_for_connection(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user