-
-
Notifications
You must be signed in to change notification settings - Fork 985
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
Overwriting the Existing record #361
Comments
Well you could do this by defining the value that is being overwritten in the database separately from the session. that way you can control the access to that value separately. Thusly can do a read/write lock/mutex (most sql databases do this) on the row so that only one of those requests can be processed at a time and there then is no race condition (assuming you are using a database which can row lock otherwise you will have to use an application defined mutex for a virtual row lock and have your application check grab the lock before reading / writing the value to assure it's the only one read/writing and that it's not going to be read/written until it unlocks it). |
@gabeio Thanks for your response. |
server side? or client side (there's a huge difference) |
Sorry for the delay. |
This would be a behavior that would need to be done with your store module; this module simply hands all the data to your store module, which can decide how to persist it to the database (either complete overwrite, or something else).
This would also be an operation done by your store module. The store module you are using has access to all the session expirations, etc. You can pretty much think of this module as being the glue between the request and your session store, exposed to Express. Any time a request comes in, this module simply asks your store module to find it, and when complete, tells the store module to persist it. This module would not have a way to track it, since it doesn't have access to the underlying database. This module lives in the memory of your Express server, and can only work on that information. For example, if you scale your Express app to 15 servers, if sess#1 was seen by server#4 to expire in 2 hours, then server#4 never way that session again since it kept hitting other servers, you would not want to accidentally think the session expired 2 hours after server#4 saw it, even though it has not expired, as it was active still. |
Thanks for the info @dougwilson :) |
I have 2 parallel requests(R1 and R2) . Both of them write some data in the record(record D1). So it's kind of race condition. If R1 writes something to the D1 and it gets persisted, then R2 writes something to the in-memory copy of D1 and saves it which results in loss of data written by R1(vice versa).
Is there anyway where we can write the only diff in the record instead of overwriting the whole record
The text was updated successfully, but these errors were encountered: