Page MenuHomePhabricator

update.php leaves unopenable UIDGenerator lock file
Open, NormalPublic

Description

This is related to bug 44850.

When I run php maintenance/update.php to install the Flow extension, it creates temp files

-rw-rw-r-- 1 spage wikidev 28 2013-08-29 06:46 /tmp/mw-UIDGenerator-UID-128
-rw-rw-r-- 1 spage wikidev 12 2013-08-29 06:46 /tmp/mw-UIDGenerator-UID-nodeid

then, when I try to access a page like Special:Flow/Sandbox, PHP fails with

Could not open '/tmp/mw-UIDGenerator-UID-128'.
Backtrace:

#0 /srv/mediawiki/includes/UIDGenerator.php(150): UIDGenerator->getTimestampAndDelay('lockFile128', 16384, 1048576)
#1 /srv/mediawiki/extensions/Flow/includes/Model/UUID.php(31): UIDGenerator::newTimestampedUID128(16)
#2 /srv/mediawiki/extensions/Flow/includes/Model/Workflow.php(73): Flow\Model\UUID::create()

the workaround is to remove these files after running update.php

It would be better if update cleaned up, or if UIDGenerator could clean up at termination it would fix bug 44850 as well.


Version: 1.22.0
Severity: normal
See Also:
https://bugzilla.wikimedia.org/show_bug.cgi?id=44850

Details

Reference
bz53791

Event Timeline

bzimport raised the priority of this task from to Normal.Nov 22 2014, 1:52 AM
bzimport set Reference to bz53791.
bzimport added a subscriber: Unknown Object (MLST).
Spage created this task.Sep 5 2013, 5:36 AM

Still current. We just got this again, on terbium, with the /usr/local/bin/characterEditStatsTranslate script for bug 58440. The script is run as mwdeploy:mwdeploy and has read permission, but not write permission, on that file, currently dated Mar 16 20:02.

Warning: fopen(/tmp/mw-UIDGenerator-squidhtcppurge-48): failed to open stream: Permission denied in

/usr/local/apache/common-local/php-1.23wmf18/includes/utils/UIDGenerator.php on line 296

[7e60e1e9] [no req] Exception from line 301 of

/usr/local/apache/common-local/php-1.23wmf18/includes/utils/UIDGenerator.php: Could not open
'/tmp/mw-UIDGenerator-squidhtcppurge-48'.

Backtrace:
#0 /usr/local/apache/common-local/php-1.23wmf18/includes/utils/UIDGenerator.php(247):

UIDGenerator->getSequentialPerNodeIDs(string, integer, integer, integer)

#1 /usr/local/apache/common-local/php-1.23wmf18/includes/deferred/SquidUpdate.php(222):

UIDGenerator::newSequentialPerNodeIDs(string, integer, integer, integer)

#2 /usr/local/apache/common-local/php-1.23wmf18/includes/deferred/SquidUpdate.php(145): SquidUpdate::HTCPPurge(array)
#3 /usr/local/apache/common-local/php-1.23wmf18/includes/deferred/SquidUpdate.php(124): SquidUpdate::purge(array)
#4 /usr/local/apache/common-local/php-1.23wmf18/includes/Title.php(3604): SquidUpdate->doUpdate()
#5 /usr/local/apache/common-local/php-1.23wmf18/includes/WikiPage.php(3128): Title->purgeSquid()
#6 /usr/local/apache/common-local/php-1.23wmf18/includes/WikiPage.php(2210): WikiPage::onArticleEdit(Title)
#7 /usr/local/apache/common-local/php-1.23wmf18/includes/WikiPage.php(1874): WikiPage->doEditUpdates(Revision, User, array)
#8 /usr/local/apache/common-local/php-1.23wmf18/maintenance/edit.php(90): WikiPage->doEditContent(WikitextContent, string,

integer)

#9 /usr/local/apache/common-local/php-1.23wmf18/maintenance/doMaintenance.php(104): EditCLI->execute()
#10 /usr/local/apache/common-local/php-1.23wmf18/maintenance/edit.php(106): require_once(string)
#11 /usr/local/apache/common-local/multiversion/MWScript.php(97): require_once(string)
#12 {main}

hoo added a comment.Mar 27 2014, 5:48 PM

(In reply to Nemo from comment #1)

Still current. We just got this again, on terbium, [...]

The terbium issues have been resolved locally for now, let's hope that this won't come back.

Change 121549 had a related patch set uploaded by BryanDavis:
Make UIDGenerator cache files world writable

https://gerrit.wikimedia.org/r/121549

Change 121549 abandoned by BryanDavis:
Make UIDGenerator cache files world writable

Reason:
Aaron and Chris are right in pointing out that this is not a good way to solve this problem. For production hosts we should never see this issue if mwscript is being used to execute all maintenance scripts.

If we do have file ownership problems on a production host that can be traced to UIDGenerator cache file permissions that should be treated as toolchain problem to be resolved by ensuring that the proper wrapper scripts are being used.

https://gerrit.wikimedia.org/r/121549

bd808 added a comment.Apr 8 2014, 11:39 PM

For production hosts we should never see this issue if mwscript is being used to execute all maintenance scripts. If we do have file ownership problems on a production host that can be traced to UIDGenerator cache file permissions that should be treated as toolchain problem to be resolved by ensuring that the proper wrapper scripts are being used.

The problem S ran into looks to be on a local/vagrant/labs dev server. I think the best answer for this is to advocate good script execution hygiene. I don't know if there is a good way to enforce this programmatically, but wiki maintenance scripts should always be run as the web server user (usually www-data on Ubuntu using Apache). If you run a maintenance script as a more privileged user you run the risk of executing malicious code that could do any number of nasty things as "you".

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptAug 17 2015, 1:23 PM
Liuxinyu970226 set Security to None.Dec 6 2015, 1:44 AM
Liuxinyu970226 added a subscriber: Liuxinyu970226.
aude added a subscriber: aude.Feb 11 2016, 12:57 PM

I just tried to install Flow, and still get this locally when clicking submit on Special:EnableFlow

bd808 added a comment.Feb 11 2016, 4:15 PM

I just tried to install Flow, and still get this locally when clicking submit on Special:EnableFlow

Running a maintenance script as a user that is not the web server user will cause this every time. The issue is that UIDGenerator stores local state in temp files that become owned by the user that first generates a UUID.

Using MW 1.28.2, I'm facing the same problem:

[060bc67ef212156a3ef32803] /index.php/Talk:Main_Page RuntimeException from line 442 of /var/www/includes/utils/UIDGenerator.php: Could not open '$IP/images/temp/mw-UIDGenerator-UID-88'.

Backtrace:

#0 /var/www/includes/utils/UIDGenerator.php(120): UIDGenerator->getTimeAndDelay(string, integer, integer, integer)
#1 /var/www/extensions/Flow/includes/Model/UUID.php(157): UIDGenerator::newTimestampedUID88(integer)
#2 /var/www/extensions/Flow/includes/Model/Workflow.php(157): Flow\Model\UUID::create()
#3 /var/www/extensions/Flow/includes/WorkflowLoaderFactory.php(97): Flow\Model\Workflow::create(string, Title)
#4 /var/www/extensions/Flow/includes/Actions/Action.php(105): Flow\WorkflowLoaderFactory->createWorkflowLoader(Title)
#5 /var/www/extensions/Flow/includes/Actions/ViewAction.php(20): Flow\Actions\FlowAction->showForAction(string, OutputPage)
#6 /var/www/extensions/Flow/includes/Actions/Action.php(50): Flow\Actions\ViewAction->showForAction(string)
#7 /var/www/includes/MediaWiki.php(495): Flow\Actions\FlowAction->show()
#8 /var/www/includes/MediaWiki.php(289): MediaWiki->performAction(Article, Title)
#9 /var/www/includes/MediaWiki.php(851): MediaWiki->performRequest()
#10 /var/www/includes/MediaWiki.php(512): MediaWiki->main()
#11 /var/www/index.php(43): MediaWiki->run()
#12 {main}

Even though I ran all maintenance scripts as the server user www-data which also has ownership of the temp folder. What's worse is that I can't find any file like that in the temp folder! Is there any workaround for this?

bd808 added a comment.May 30 2017, 3:24 AM

Using MW 1.28.2, I'm facing the same problem:

[060bc67ef212156a3ef32803] /index.php/Talk:Main_Page RuntimeException from line 442 of /var/www/includes/utils/UIDGenerator.php: Could not open '$IP/images/temp/mw-UIDGenerator-UID-88'.
Even though I ran all maintenance scripts as the server user `www-data` which also has ownership of the temp folder. What's worse is that I can't find any file like that in the temp folder! Is there any workaround for this?

Based on the paths in the trace, the script is probably trying to open /var/www/images/temp/mw-UIDGenerator-UID-88. The error could be caused by either an existing file owned by another user or the user executing the script not having write permission to the /var/www/images/temp directory. Besides fixing the permissions on existing files/directories, $wgTmpDirectory could be changed to point to another location if that was more desirable.

We probably should have closed this bug as 'declined' years ago per the comments on https://gerrit.wikimedia.org/r/#/c/121549/.

The error could be caused by either an existing file owned by another user or the user executing the script not having write permission to the /var/www/images/temp directory

ls -al /var/www/images 
total 20
drwxrwxrwx  3 www-data www-data 4096 May 31 13:40 .
drwxr-xr-x 20 root     root     4096 May 31 13:40 ..
-rwxrwxrwx  1 www-data www-data  252 May 26 18:12 .htaccess
-rwxrwxrwx  1 www-data www-data   84 May 26 18:12 README
drwxrwxrwx  2 www-data www-data 4096 May 31 13:40 temp

ls -al /var/www/images/temp
total 8
drwxrwxrwx 2 www-data www-data 4096 May 31 13:40 .
drwxrwxrwx 3 www-data www-data 4096 May 31 13:40 ..

And I still have the same error on all talk pages!

kostajh added a subscriber: kostajh.Nov 5 2018, 9:57 PM

@Calexit a little late, but fwiw I had to also run touch mw-UIDGenerator-UID-88 in the temp directory.

Sophivorus added a subscriber: Sophivorus.EditedMar 13 2019, 1:06 PM

I got this same issue on my wiki in a VPS. Solution was to reboot the server to empty the tmp directory.

Suddenly on my wiki after the latest upgrade:

This is left sitting around after running update.php:
/tmp/mw-UIDGenerator-UID-nodeid

And this is left sitting around each day by some other process:
/tmp/mw-UIDGenerator-UUID-128

Please clean them up.

Also by the way, what if more than one wiki is installed on a shared server by more than one user?