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

feat: Handle database connection errors with 500 #725

Merged
merged 2 commits into from
Feb 17, 2021

Conversation

chriswk
Copy link
Contributor

@chriswk chriswk commented Feb 16, 2021

  • If database goes away while unleash is running, unleash now stays
    running, but all api endpoints will return 500.
  • This includes our health endpoint, which allows k8s or similar
    orchestrators to decide what should be done, rather than Unleash
    terminating unexpectedly

@coveralls
Copy link

coveralls commented Feb 16, 2021

Coverage Status

Coverage decreased (-0.2%) to 95.587% when pulling de8a4a6 on database-disconnect-handling into f49b508 on master.

src/lib/metrics.js Outdated Show resolved Hide resolved
fields,
);
res.json({ version, features });
try {
Copy link
Member

@ivarconr ivarconr Feb 16, 2021

Choose a reason for hiding this comment

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

would it make sense to move all these "try/catch" calls to the "base-controller" class?
(seems like we are always doing the same thing)

Copy link
Contributor Author

@chriswk chriswk Feb 16, 2021

Choose a reason for hiding this comment

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

That would then probably mean adding a error-handling-middleware, cause the controller base class method doesn't actually have access to req or res

Copy link
Member

Choose a reason for hiding this comment

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

hmz. I was not aware of that.

Copy link
Member

Choose a reason for hiding this comment

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

Let leave it like this for now then. Could be that the controller should have access to req/res, on the other hand, it then starts to smell like a custom middleware.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, seeing as how we're calling the same util/handleErrors method for almost all of them, writing a custom error-handling middleware might be just what we want.

return addons;
} catch (e) {
this.logger.warn(`Could not get addons ${e}`);
return [];
Copy link
Member

Choose a reason for hiding this comment

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

I would actually argue that we should store the addon configurations and return the cached / stale once if we are unable to fetch the configs. Now we are ending up removing them, and not doing "addon" logic in the case the db is removed. It can lead to lost messages to a webhook (because of a temporary db-error).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How would we store them, what does memoizee do if we don't return anything from a call instead of the empty list?

Copy link
Member

Choose a reason for hiding this comment

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

Need to check the docs. I do not think memoizee do anything clever automatically.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see errors are not cached, but it also seems to void the cache for the key that fails. So it wasn't enough to simply not have error handling inside the memoizee wrapper

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like it already does what we want. Does not cache a promise that errors, but does not crash the application either, it simply retries the wrapped function the next time we need the data. I reverted to how it looked on master for just this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Which isn't what we want. We do want to keep the stale config. Hmm, let's discuss this tomorrow

- If database goes away while unleash is running, unleash now stays
  running, but all api endpoints will return 500.
- This includes our health endpoint, which allows k8s or similar
  orchestrators to decide what should be done, rather than Unleash
  terminating unexpectedly
@chriswk chriswk merged commit 8bf4214 into master Feb 17, 2021
@ivarconr ivarconr deleted the database-disconnect-handling branch June 3, 2022 10:03
Tymek pushed a commit that referenced this pull request Aug 26, 2022
Bumps [nanoid](https://github.com/ai/nanoid) from 3.1.28 to 3.3.1.
- [Release notes](https://github.com/ai/nanoid/releases)
- [Changelog](https://github.com/ai/nanoid/blob/main/CHANGELOG.md)
- [Commits](ai/nanoid@3.1.28...3.3.1)

---
updated-dependencies:
- dependency-name: nanoid
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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.

None yet

3 participants