shpasser / GaeSupportL5

Google App Engine Support package for Laravel 5
MIT License
160 stars 27 forks source link

Exclusive lock in Filesystem.php line 81 #63

Closed digitalhuman closed 7 years ago

digitalhuman commented 8 years ago

When running on GAE you might get this exclusive file lock error in Laravel v5.1.44. To fix this edit:

"vendor\laravel\framework\src\Illuminate\Filesystem\Filesystem.php", goto line 81:

Change: LOCK_EX to LOCK_SH

Update your GAE code and your good to go.

shpasser commented 8 years ago

This change does not seem right to me for several reasons:

  1. file_put_contents() does not accept LOCK_SH parameter according to PHP docs,
  2. You can use LOCK_SH with flock() to acquire a reader lock, but put() is a write operation,
  3. If put() function is required to lock the file exclusively it would be incorrect to ignore the lock parameter.
shpasser commented 8 years ago

Anyway, I would be interested to know how to reproduce the issue in order to try to understand whether something could be done in order to prevent it from happening.

digitalhuman commented 8 years ago

Interesting thing. I guess its just not documented cause it actually does work. Anyway;

Assuming you have a project in GAE, a valid Bucket and MySQL DB etc etc setup and working.

1) Started with a clean Larvel v5.1.44 clone created with composer. 2) Then added "shpasser/gae-support-l5": "~1.0" 3) composer update 4) added Shpasser\GaeSupportL5\GaeSupportServiceProvider::class 5) php artisan gae:setup --config --cache-config --bucket="your-bucket-id" --db-socket="cloud-sql-instance-socket-connection-string" --db-name="cloud-sql-database-name" --db-host="cloud-sql-instance-ipv4-address" app-id 6) Copied .env-production to .env 7) appcfg.py update ./

Thats what I did and the error occurred. After changing it to LOCK_SH stuff worked fine.

shpasser commented 8 years ago

Could you please add the log messages with the stack trace?

systemsix commented 7 years ago

I also have the same problem.

  1. in Filesystem.php line 81
  2. at HandleExceptions->handleError('2', 'file_put_contents(): Exclusive locks may only be set for regular files', '/base/data/home/apps/b~app-id/20161125t075045.397300659245909413/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php', '81', array('path' => 'gs://app-id.appspot.com/storage/framework/sessions/af229674daaa9cfbdfefa88f6eb426c6cae98c44', 'contents' => 'a:4:{s:6:"_token";s:40:"k38z37v29M19F7eeT6TzUHLrpGRWFippmAnuthGL";s:9:"_previous";a:1:{s:3:"url";s:32:"https://app-id.appspot.com";}s:9:"_sf2_meta";a:3:{s:1:"u";i:1480060506;s:1:"c";i:1480060506;s:1:"l";s:1:"0";}s:5:"flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}}', 'lock' => true))
  3. at file_put_contents('gs://app-id.appspot.com/storage/framework/sessions/af229674daaa9cfbdfefa88f6eb426c6cae98c44', 'a:4:{s:6:"_token";s:40:"k38z37v29M19F7eeT6TzUHLrpGRWFippmAnuthGL";s:9:"_previous";a:1:{s:3:"url";s:32:"https://app-id.appspot.com";}s:9:"_sf2_meta";a:3:{s:1:"u";i:1480060506;s:1:"c";i:1480060506;s:1:"l";s:1:"0";}s:5:"flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}}', '2') in Filesystem.php line 81
  4. at Filesystem->put('gs://app-id.appspot.com/storage/framework/sessions/af229674daaa9cfbdfefa88f6eb426c6cae98c44', 'a:4:{s:6:"_token";s:40:"k38z37v29M19F7eeT6TzUHLrpGRWFippmAnuthGL";s:9:"_previous";a:1:{s:3:"url";s:32:"https://app-id.appspot.com";}s:9:"_sf2_meta";a:3:{s:1:"u";i:1480060506;s:1:"c";i:1480060506;s:1:"l";s:1:"0";}s:5:"flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}}', true) in FileSessionHandler.php line 83
  5. at FileSessionHandler->write('af229674daaa9cfbdfefa88f6eb426c6cae98c44', 'a:4:{s:6:"_token";s:40:"k38z37v29M19F7eeT6TzUHLrpGRWFippmAnuthGL";s:9:"_previous";a:1:{s:3:"url";s:32:"https://app-id.appspot.com";}s:9:"_sf2_meta";a:3:{s:1:"u";i:1480060506;s:1:"c";i:1480060506;s:1:"l";s:1:"0";}s:5:"flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}}') in Store.php line 262
  6. at Store->save() in StartSession.php line 88
  7. at StartSession->terminate(object(Request), object(Response)) in Kernel.php line 145
  8. at Kernel->terminate(object(Request), object(Response)) in index.php line 58
shpasser commented 7 years ago

In this case a wrong .env file is being used since Laravel uses file session driver. While running on GAE memcached session driver is the appropriate one.

shpasser commented 7 years ago

BTW, locks are not supported on GCS buckets. https://cloud.google.com/appengine/docs/php/googlestorage/advanced

shpasser commented 7 years ago

Please check the status of the issue after my latest reply. If indeed the issue was caused by a wrong .env file I would like to close it.

systemsix commented 7 years ago

I'm using memcached. Here is my .env.

APP_ENV=production APP_DEBUG=false APP_KEY=APP_KEY DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_DATABASE=homestead DB_USERNAME=homestead DB_PASSWORD=secret CACHE_DRIVER=memcached SESSION_DRIVER=memcached QUEUE_DRIVER=gae REDIS_HOST=127.0.0.1 REDIS_PASSWORD= REDIS_PORT=6379 MAIL_DRIVER=gae MAIL_HOST=mailtrap.io MAIL_PORT=2525 MAIL_USERNAME= MAIL_PASSWORD= MAIL_ENCRYPTION= APP_LOG=syslog FILESYSTEM=gae CACHE_SERVICES_FILE=false CACHE_CONFIG_FILE=false CACHE_ROUTES_FILE=false CACHE_COMPILED_VIEWS=false

shpasser commented 7 years ago

The only other option is that you have a cached config with wrong parameters. Please try to remove bootstrap/cache/config.php and then push your app to GAE. If the suggested way works you will have to cache the configuration again using gae:setup command.

systemsix commented 7 years ago

You were spot on! Thank you!

skipatrol commented 7 years ago

I had the same "exclusive locks" issue and shpasser's solution worked for me as well. I removed bootstrap/cache/config.php and deployed the app, which worked. Then I ran the gae:setup command again, overwrote the files when prompted, deployed the app and it is still working. Thank you!

shpasser commented 7 years ago

It seems like a good time to close this one.