lzztt / koa-session-minimal

Minimal implementation of session middleware for Koa 2
MIT License
75 stars 13 forks source link

saveSession is asynchronous function? #25

Open DreamMoon93 opened 3 months ago

DreamMoon93 commented 3 months ago

Q: Sometimes there may be some problems with mysql db, resulting in slower storage. Sometimes when saving the session, it may not be successful, and the client will initiate a request to obtain the value of the session. Since saveSession is an asynchronous operation, it is possible to obtain the current session value or the value that has not been updated in history。

Should we add await to saveSession to synchronize the storage session?

lzztt commented 1 month ago

I think adding await won't solve the problem, as saveSession() is the last action for a request. There is no further action after it to benefit from the synchronization.

When the underneath store is slow to commit an update, or having a replication delay if it's distributed, it's possible that the next request reads the previous version of session state from the session store.