php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80904 non-atomic behaviour when changing symlinked doc-root
Submitted: 2021-03-24 17:23 UTC Modified: 2021-03-24 17:28 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: maggus dot staab+php at googlemail dot com Assigned:
Status: Open Package: *General Issues
PHP Version: 7.4.16 OS: ubuntu linux 20 lts
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
44 - 14 = ?
Subscribe to this entry?

 
 [2021-03-24 17:23 UTC] maggus dot staab+php at googlemail dot com
Description:
------------
we are experiencing errors when deploying new code/updates onto our servers.

these are rare errors which happen after the deployment tool swaps the doc-root symlink. we are using a popular deployment tool from https://deployer.org/

I guess what triggers our error can be described as the following
- http request are comig in
- apache server receives the request, resolves the doc-root symlink and starts processing the request with version A of our codebase
- a deployment happens which swaps the symlink of the doc-root to version A+1
- the request, which was started before, realizes the symlink switched and while serving a request now picks up changes from app version A+1

this leads to errors like "Cannot redeclare function", "class already defined" and sometimes we even see errors like out-of-memory.



from our error reporting its pretty clear that requests mix classes from codebase in version A and version A+1:

App Path:           /www/myapp/releases/234/app/www-phone
Request-Id:         118c703

Exception:          'ErrorException' with message 'Cannot redeclare renderTrackableOrderBySelect() (previously declared in /www/myapp/releases/234/vendor/plugins/clxMobileNetPortable/lib/portable/helpers/ViewHelper.php:442)' (1)

the stacktrace from this error contains the path to version A+1, while the initial App-Path which is set very early in the bootsrap as a php constant, was defined as Version A.


I feel/guess the problem we experience is the one which rasmus created this apache module for: https://github.com/etsy/mod_realdoc

in our setup we are running php in mpm event mode, which the mentioned apache module does not work with (per README notes).
the underlying issue seems to be discussed here: https://github.com/etsy/mod_realdoc/issues/4

I hope for some inspiration/pointers on how this problem could be tackled or which tools/mods should/can be used to circumvent the problem reported.

feel free to ask further questions in case I missed some important information

Test script:
---------------
the errors happen only from time to time and cannot be reproduced easily.
I guess I can not really provide a test-script.

Expected result:
----------------
a php request should be atomic and should not change the doc-root while the request is running


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-03-24 17:28 UTC] maggus dot staab+php at googlemail dot com
it seems I cannot edit the initial bug description, therefore here a small correction.

our error reporting shows

App Path:           /www/myapp/releases/233/app/www-phone
Request-Id:         118c703

Exception:          'ErrorException' with message 'Cannot redeclare renderTrackableOrderBySelect() (previously declared in /www/myapp/releases/234/vendor/plugins/clxMobileNetPortable/lib/portable/helpers/ViewHelper.php:442)' (1)


see different app revision in 'App Path' vs. 'Exception Stack Trace'.
in the initial report I copy & paste'd the wrong numbers.
 [2021-04-22 09:31 UTC] maggus dot staab+php at googlemail dot com
after reading https://www.php.net/manual/de/opcache.configuration.php#ini.opcache.file_update_protection

I stumbled over "opcache.dups_fix bool  - This hack should only be enabled to work around "Cannot redeclare class" errors. "

should I activate this flag because of the errors I see?
or will it just ignore the errors but still get stuck?
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Jul 25 06:01:24 2021 UTC