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

Integrate timeouts into lock acqusition #2

Closed
CMCDragonkai opened this issue Mar 31, 2022 · 0 comments · Fixed by #3
Closed

Integrate timeouts into lock acqusition #2

CMCDragonkai opened this issue Mar 31, 2022 · 0 comments · Fixed by #3
Assignees
Labels
development Standard development r&d:polykey:core activity 1 Secret Vault Sharing and Secret History Management

Comments

@CMCDragonkai
Copy link
Member

Specification

If we need to be able to "retry" locking due to deadlocks MatrixAI/Polykey#294 (comment).

Then we would need to integrate the withTimeout and tryAcquire decorators from async-mutex. They can be represented with parameters to our acquireRead and acquireWrite. But that would also mean we have to lambda-abstract them.

public read(timeout?: number): ResourceAcquire<RWLockWriter> {
  // by default timeout: undefined
  // but if 0, use tryAcquire
  // if above 0, use withTimeout
  return async () => {
    // same contents as this.acquireRead()
  };
}

Note that when timed out, an exception is thrown. We don't actually retry here. It is up to the user of the lock to attempt to call again, in case they need some random jitter delay.

We can keep the acquireRead method if we want to preserve the API. Or expect users to just do this.read() and this.write() with the relevant timeouts.

Additional context

Tasks

  1. Import withTimeout and tryAcquire from async-mutex
  2. Add in read and write methods that have a timeout parameter
  3. Usage is now like withF([rwLock.read(1000)], async ([lock]) => ...)
  4. Add timeout parameters to withRead and withWrite variants too as the second parameter after f and g for function and generator variants.
@CMCDragonkai CMCDragonkai added the development Standard development label Mar 31, 2022
@CMCDragonkai CMCDragonkai self-assigned this Apr 12, 2022
@teebirdy teebirdy added the r&d:polykey:core activity 1 Secret Vault Sharing and Secret History Management label Jul 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
development Standard development r&d:polykey:core activity 1 Secret Vault Sharing and Secret History Management
Development

Successfully merging a pull request may close this issue.

2 participants