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

Add possibility to use locking with DynamoDB sessions #1676

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

valtzu
Copy link

@valtzu valtzu commented Mar 3, 2024

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.

@valtzu valtzu force-pushed the add-dynamodb-session-locking branch 2 times, most recently from ef20bb1 to 524c26d Compare March 3, 2024 16:54
@valtzu valtzu force-pushed the add-dynamodb-session-locking branch from 524c26d to 781163e Compare March 3, 2024 17:06
Copy link
Member

@jderusse jderusse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly,
Lock is acquired when reading the session
and released when writing the session.

This sound really fragile to me.

  • What if session is written several time?
  • What if the session is not written (just read and close)
  • What if the app crashes before writing the session? Session will stay locked forever?

The last question make me think, this is not the right way, and we should use symfony/lock in a decorator instead

src/Integration/Aws/DynamoDbSession/src/SessionHandler.php Outdated Show resolved Hide resolved
src/Integration/Aws/DynamoDbSession/src/SessionHandler.php Outdated Show resolved Hide resolved
src/Integration/Aws/DynamoDbSession/src/SessionHandler.php Outdated Show resolved Hide resolved
$options['consistent_read'] = $options['consistent_read'] ?? true;
$options['locking'] = (bool) ($options['locking'] ?? false);
$options['max_lock_wait_time'] = (float) ($options['max_lock_wait_time'] ?? 10.0);
$options['min_lock_retry_microtime'] = (int) ($options['min_lock_retry_microtime'] ?? 10000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure such thing deserve parameters.

Copy link
Author

@valtzu valtzu Mar 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand DynamoDB usually is billed per-request, so giving a possibility to fine-tune these according to your use case may be useful in terms of balancing the functionality & cost-savings. For example, if your sessions usually are locking for several seconds, you likely don't want to be polling every 10-50ms (which again is the default from official sdk).

Also, these settings are just copied from aws-sdk to make a migration to async-aws as small change as possible.

@valtzu
Copy link
Author

valtzu commented Mar 3, 2024

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.

if (false !== $id && ($this->sessionId !== $id || !$this->sessionWritten)) {
$this->sessionWritten = $this->doWrite($id, false);


What if session is written several time?

  1. I belive the official aws-sdk has the same "issue" (maybe it's a non-issue because of number 2)
  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?

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

Successfully merging this pull request may close these issues.

2 participants