roccomuso / memorystore

express-session full featured MemoryStore layer without leaks!
MIT License
120 stars 20 forks source link

MemoryStore has no exit method and keeps the process up. #24

Closed eavdmeer closed 3 years ago

eavdmeer commented 3 years ago

If all other resources in my program exit, which should stop the program, it keeps running because of MemoryStore:

    store: this.config.sessionsPersistent ?
      new FileStore({ path: this.config.sessionDir, ttl: ttl }) :
      new MemoryStore({ checkPeriod: ttl * 1000 }),

With FileStore, the process exits. With MemoryStore, it hangs.

roccomuso commented 3 years ago

Did you call stopInterval on your memorystore instance?

https://github.com/roccomuso/memorystore/blob/master/lib/memorystore.js#L280

I might add an unref in a near future: https://httptoolkit.tech/blog/unblocking-node-with-unref/#timeoutunref to avoid memorystore from keeping the process alive.

eavdmeer commented 3 years ago

That's actually a very good point. I did not stop the interval time. I'll have a look at it first thing in the morning! Thanks!

eavdmeer commented 3 years ago

I can confirm that this works as it should. After calling stopInterval(), the process exits correctly.

copmerbenjamin commented 2 years ago

Just for info: Unref was implemented in https://github.com/roccomuso/memorystore/commit/e16e29b86c08588c0ecf1642e6264c40364a8ade and released in 1.6.7