mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-03-13 11:35:56 +01:00
fail longpolling endpoint after 45 seconds.
this should fix a possible bug in which connections are left open forever or worse.
This commit is contained in:
parent
1b433f9cbc
commit
6f88973f75
1 changed files with 21 additions and 3 deletions
|
@ -32,6 +32,24 @@ async def api_public_payment_longpolling(payment_hash):
|
|||
print("adding standalone invoice listener", payment_hash, send_payment)
|
||||
api_invoice_listeners.append(send_payment)
|
||||
|
||||
async for payment in receive_payment:
|
||||
if payment.payment_hash == payment_hash:
|
||||
return jsonify({"status": "paid"}), HTTPStatus.OK
|
||||
response = None
|
||||
|
||||
async def payment_info_receiver(cancel_scope):
|
||||
async for payment in receive_payment:
|
||||
if payment.payment_hash == payment_hash:
|
||||
nonlocal response
|
||||
response = (jsonify({"status": "paid"}), HTTPStatus.OK)
|
||||
cancel_scope.cancel()
|
||||
|
||||
async def timeouter(cancel_scope):
|
||||
await trio.sleep(45)
|
||||
cancel_scope.cancel()
|
||||
|
||||
async with trio.open_nursery() as nursery:
|
||||
nursery.start_soon(payment_info_receiver, nursery.cancel_scope)
|
||||
nursery.start_soon(timeouter, nursery.cancel_scope)
|
||||
|
||||
if response:
|
||||
return response
|
||||
else:
|
||||
return jsonify({"message": "timeout"}), HTTPStatus.REQUEST_TIMEOUT
|
||||
|
|
Loading…
Add table
Reference in a new issue