colopl / laravel-spanner

Laravel database driver for Google Cloud Spanner
Apache License 2.0
97 stars 16 forks source link

fix: separate auth cache and session pool to prevent race condition #152

Closed taka-oyama closed 11 months ago

taka-oyama commented 11 months ago

Coming from https://github.com/googleapis/google-cloud-php/issues/6703#issuecomment-1846328959

Auth does not lock the cache file, so it's possible for a race condition to occur.

Below is an example of how that may happen.

  1. Process 1: Auth opens cache
  2. Process 2: Session Pool opens cache
  3. Process 2: Session Pool creates a session and saves (file is written)
  4. Process 1: Auth writes to cache (file is overwritten and session created at 3. no longer exists in cache)

Must be backported to 6.0.