Add possibility to use locking with DynamoDB sessions
DynamoDB session handler in this library not supporting session locking makes it really difficult to migrate applications using the official AWS SDK with locking (or default file handler with locking) to async-aws/dynamo-db-session.
Unless there are some valid arguments not to support locking, I'd propose let's add it.
Thanks for the quick review @jderusse!
Lock is acquired when reading the session and released when writing the session. This sound really fragile to me.
The logic is mostly copied from the official aws-sdk, so if you think it's fragile, then the official sdk is fragile?
What if the session is not written (just read and close)
On close the the expires is updated if a write didn't occur, so we're already doing a write even when there are no changes.
https://github.com/async-aws/aws/blob/bc92ccef1214cefac04d6fcb862f2b6df6242862/src/Integration/Aws/DynamoDbSession/src/SessionHandler.php#L115-L116
What if session is written several time?
- I belive the official aws-sdk has the same "issue" (maybe it's a non-issue because of number 2)
- Is it even possible? As I see php only has
session_write_close, there is no method to trigger write without close? Of course if you don't use the native interface, then yeah
What if the app crashes before writing the session? Session will stay locked forever?
Right now, correct, the same as with the official aws-sdk. But of course we could store a timestamp in lock instead of boolean to have some timeout after which the entry would be no longer considered locked.
we should use symfony/lock in a decorator instead
While in general I like the idea, I'm not sure how great that would be in terms of performance, integrity & reliability (having separate storage/requests/connections for locks etc) + again it would defeat the purpose of this PR which is to make it easier to migrate from aws-sdk or native file-based PHP session handling to this library.
If we were to use symfony/lock instead, would such decorator have a place in this project or you meant it as a suggestion to just use symfony/lock and write a decorator in my project?