Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@dni
Copy link
Member

@dni dni commented Feb 21, 2024

error is not raised, even if failed webhook would be marked as sent every time

@codecov
Copy link

codecov bot commented Feb 21, 2024

Codecov Report

Attention: Patch coverage is 0% with 18 lines in your changes are missing coverage. Please review.

Project coverage is 58.55%. Comparing base (5b43989) to head (cf9bd03).

Files Patch % Lines
lnbits/core/tasks.py 0.00% 18 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #2289      +/-   ##
==========================================
- Coverage   58.63%   58.55%   -0.09%     
==========================================
  Files          61       61              
  Lines        9192     9205      +13     
==========================================
  Hits         5390     5390              
- Misses       3802     3815      +13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dni dni changed the title fix: webhook sent raise a failed request fix: raise failed request to not run mark_webhook_sent Feb 21, 2024
@dni dni added this to the 0.12.3 milestone Feb 21, 2024
@motorina0
Copy link
Collaborator

In dispatch_webhook the status code is set to -1 in case of failure. We should be consistent in handling the error.

        try:
            r = await client.post(payment.webhook, json=data, timeout=40)
            await mark_webhook_sent(payment, r.status_code)
        except (httpx.ConnectError, httpx.RequestError):
            await mark_webhook_sent(payment, -1)

There are 3 places where this pattern ☝️ is repeated.
A common function should be extracted: call_webhook(payment, data, timeout)

@dni dni force-pushed the bug-webhook-send branch from 5742f68 to 80d41f6 Compare February 23, 2024 08:17
@dni
Copy link
Member Author

dni commented Feb 23, 2024

i was actually misinterpreting the code, we don't want to raise an HTTPStatusException here, because we actually want to set the status code to 404 or 500 if it fails to see if the response was not ok. we just want to set status -1 when we cannot even send the request.

i also saw that mark_webhook_sent is actually saved twice, for payment.webhook and for balance_notify which i think is kind of weird.

@motorina0 motorina0 self-requested a review February 27, 2024 08:14
)
await switch_to_voidwallet()
except (httpx.ConnectError, httpx.RequestError):
except (httpx.RequestError, httpx.HTTPStatusError):
Copy link
Collaborator

@motorina0 motorina0 Feb 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is httpx.ConnectError not ever thrown?
Can we just catch Error and log the actual error?
Is there a case when the error should bubble up (and stop the loop)?

Copy link
Member Author

@dni dni Feb 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConnectError is capture by RequestError look at the exception tree here. it was redundant. https://www.python-httpx.org/exceptions/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

statuserror is triggerbe by raise_for_status() and is raised if the response has a bad status code

pass
r.raise_for_status()
await mark_webhook_sent(payment.payment_hash, r.status_code)
except httpx.HTTPStatusError as exc:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which is the difference between the two catch clauses (httpx.HTTPStatusError vs httpx.RequestError), why are they handled differently?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

request error is the request never reached the server, httperror is it hits the server but returns a bad statuscode

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are they handled differently though?

Copy link
Member Author

@dni dni Feb 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because we want to save the bad statuscode inside the payment details, it was like that before. so we know we did send it, but the receiver couldnt handle it.

@dni dni force-pushed the bug-webhook-send branch from b88e3a9 to 51981da Compare March 12, 2024 12:53
@dni dni requested a review from talvasconcelos March 12, 2024 12:57
@arcbtc arcbtc force-pushed the bug-webhook-send branch from 51981da to cf9bd03 Compare March 12, 2024 13:06
@motorina0 motorina0 merged commit 54dec17 into dev Mar 12, 2024
@motorina0 motorina0 deleted the bug-webhook-send branch March 12, 2024 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants