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

Allow TypeormStore to recover from failed request #19

Closed
Kehrlann opened this issue Jun 29, 2020 · 4 comments
Closed

Allow TypeormStore to recover from failed request #19

Kehrlann opened this issue Jun 29, 2020 · 4 comments

Comments

@Kehrlann
Copy link
Contributor

Kehrlann commented Jun 29, 2020

Hey there 👋
First, thanks for the lib !

We had an issue in prod the other day ; our (Postgres) database threw an exception at some point while fetching the sessions. However it was just a flake, not a complete crash of the connection. When this happens, the TypeormStore emits a disconnect event, and then never reconnects. We did a quickfix but that's nasty (see below).

I don't think the store should disconnect on every time there's an exception. Not sure what the ideal behavior would be:

  • Do not disconnect, just log the errors ? Most of the connect-xyz implementations do not emit connect/disconnect events, see Redis: https://github.com/tj/connect-redis/
  • Buffer the errors and only disconnect after a certain number of errors ?
  • Include a "reconnect" mechanism ?
  • Include a "circuit-breaker" type mechanism ?
  • Give the users a way to define a failure handler ?

Any thoughts ?


For reference, our quickfix is to do something like:

  const store = new TypeormStore({
    cleanupLimit: 2,
    ttl: 86400,
  })
    .connect(sessionRepository)
    .on("disconnect", () => setTimeout(() => store.emit("connect"), 100));

Note: The timeout is to give the disconnect event more time to propagate before we fire a connect event, I think even a 0 timeout would work.

@nykula
Copy link
Contributor

nykula commented Jun 30, 2020

Hello! I like how "Give the users a way to define a failure handler" sounds. What do you think of an option like onError: (s: Store, e: Error) => {...}?
Could you please add a failing test case that illustrates the current issue, or link me a minimal repo with reproduction? (:

Kehrlann added a commit to Kehrlann/connect-typeorm that referenced this issue Jun 30, 2020
@Kehrlann
Copy link
Contributor Author

I like onError. However, what should the default behavior be ? And should onError come on top the current implementation, or replace it entirely ?

I added a (quick and dirty) failing test case in #20

@nykula nykula closed this as completed in dd5516e Jul 6, 2020
@nykula
Copy link
Contributor

nykula commented Jul 6, 2020

Hello again, sorry for the delay, have been busy over the week. onError keeps the debug line but is called right after it instead of the disconnect event if present. Please confirm that the commit dd5516e works for your case so I publish the patch to npm, or reopen the issue if it doesn't.

@Kehrlann
Copy link
Contributor Author

Kehrlann commented Jul 7, 2020

Yep that works great, thanks !

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

No branches or pull requests

2 participants