Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(connector-besu): do not crash if ledger unreachable - send HTTP 503 #3573

Merged
merged 1 commit into from
Nov 16, 2024

Conversation

ruzell22
Copy link
Contributor

@ruzell22 ruzell22 commented Oct 4, 2024

Commit to be reviewed


fix(connector-besu): do not crash if ledger unreachable - send HTTP 503

Primary Changes
---------------
1. Yarn patch to [email protected] so that it does not crash nodejs process
Without the catch block, the rejection is an unhandled rejection that bubbles
up to the top of the callstack where NodeJS itself catches it and then crashes
the entire process. (used to be that it just logged a warning but since some
of the newer versions it crashes which allows us to find these bugs in our
code / library's code)
2. It is returning a 503 instead of a 500
3. Added a static retry-after header value of 5 seconds
4. Added test case in test-ledger which has run-transaction at the end that is
expected to give error 503 when the backing ledger is unavailable

Fixes: #3406

Pull Request Requirements

  • Rebased onto upstream/main branch and squashed into single commit to help maintainers review it more efficient and to avoid spaghetti git commit graphs that obfuscate which commit did exactly what change, when and, why.
  • Have git sign off at the end of commit message to avoid being marked red. You can add -s flag when using git commit command. You may refer to this link for more information.
  • Follow the Commit Linting specification. You may refer to this link for more information.

Character Limit

  • Pull Request Title and Commit Subject must not exceed 72 characters (including spaces and special characters).
  • Commit Message per line must not exceed 80 characters (including spaces and special characters).

A Must Read for Beginners
For rebasing and squashing, here's a must read guide for beginners.

Copy link
Contributor

@petermetz petermetz left a comment

Choose a reason for hiding this comment

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

@ruzell22 Looking good, but please add a specific test case within the run-transaction endpoint's existing test suite so that we have a specific unit test verifying that this logic now works as intended.
Please put the test case in the test-plugin-ledger-connector-besu package because that way the API server can be used as well and so it's a more complete simulation.

Copy link
Contributor

@petermetz petermetz left a comment

Choose a reason for hiding this comment

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

@ruzell22 I can't find the relevant test case that creates the scenario in question (no ledger connectivity and then assertions to verify that the API server hasn't crashed and that the response was sent back as expected).

Copy link
Contributor

@petermetz petermetz left a comment

Choose a reason for hiding this comment

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

@ruzell22 I don't see the API server being used in the tests, could you please double check?

@ruzell22
Copy link
Contributor Author

Hello @petermetz , the test is added at the end of packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts . The ledger was shutdown before it to force the ledger unavailable status when running the runTransactionV1.

image

@petermetz
Copy link
Contributor

Hello @petermetz , the test is added at the end of packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts . The ledger was shutdown before it to force the ledger unavailable status when running the runTransactionV1.

@ruzell22 When I search the source code of that test case for the word "ApiServer" it does not come up with anything (e.g. neither imported nor used from what I can tell)

The reason why I'm pushing to use the API server is because that's the NodeJS process in which the context of the plugins are running in production use-cases.

image

@jagpreetsinghsasan
Copy link
Contributor

Please fix yarn-codegen check as well @ruzell22

Primary Changes
---------------
1. Yarn patch to [email protected] so that it does not crash nodejs process
Without the catch block, the rejection is an unhandled rejection that bubbles
up to the top of the callstack where NodeJS itself catches it and then crashes
the entire process. (used to be that it just logged a warning but since some
of the newer versions it crashes which allows us to find these bugs in our
code / library's code)
2. It is returning a 503 instead of a 500
3. Added a static retry-after header value of 5 seconds
4. Added test case in test-ledger which has run-transaction at the end that is
expected to give error 503 when the backing ledger is unavailable

Fixes: hyperledger-cacti#3406

Co-authored-by: Peter Somogyvari <[email protected]>

Signed-off-by: ruzell22 <[email protected]>
Signed-off-by: Peter Somogyvari <[email protected]>
@petermetz petermetz merged commit 394323e into hyperledger-cacti:main Nov 16, 2024
131 of 137 checks passed
@petermetz petermetz deleted the issue3406 branch November 16, 2024 01:19
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.

fix(connector-besu): do not crash if ledger unreachable - send HTTP 503
4 participants