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 locking to FetchAuthTokenCache #226

Open
ericnorris opened this issue Apr 22, 2019 · 1 comment · May be fixed by #322
Open

Add locking to FetchAuthTokenCache #226

ericnorris opened this issue Apr 22, 2019 · 1 comment · May be fixed by #322
Assignees
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@ericnorris
Copy link

Per #225, filing an additional ticket for this feature request. Thanks again!

Is your feature request related to a problem? Please describe.

The SysVCacheItemPool class points out that calling code should handle race conditions, but the FetchAuthTokenCache class, which is used by the google-cloud-php library when the authCache parameter is passed in (see here), does not do any locking.

This means that users that follow code examples such as the following (from here):

$authCache = new SysVCacheItemPool();
$sessionCache = new SysVCacheItemPool([
    // Use a different project identifier for ftok than the default
    'proj' => 'B'
]);

$spanner = new SpannerClient([
    'authCache' => $authCache
]);

...may run into race condition issues unknowingly.

Describe the solution you'd like

Either of the two:

  • FetchAuthTokenCache adds a locking mechanism to safely use the passed inCacheItemPoolInterface
  • I file an issue in the google-cloud-php repository to request it use a cache with locking built in.
@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Apr 23, 2019
@jdpedrie jdpedrie added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed 🚨 This issue needs some love. triage me I really want to be triaged. labels May 2, 2019
@bshaffer bshaffer linked a pull request Feb 19, 2021 that will close this issue
14 tasks
@bshaffer
Copy link
Contributor

bshaffer commented Feb 22, 2021

I am trying to fix this for v2.0 but I can't seem to recreate the error. I can add some locking to ftok, but I'd like to confirm the fix. I've done the following:

> while [ true ]; do php -r "ftok('/tmp/foo', 'A');"; done &
> while [ true ]; do php -r "ftok('/tmp/foo', 'B');"; done

I was hoping this would eventually throw the error but it hasn't happened yet. I've also tried this:

use Google\Cache\SysVCacheItemPool;

while (true) {
    $rand = rand() % 256;
    $key = chr($rand);
    $var = 'varname' . $key;
    $$var = new Google\Cache\SysVCacheItemPool(['proj' => $key]);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants