[wp-trac] [WordPress Trac] #53705: Plugin upgrade deletes files from other in-progress upgrades
WordPress Trac
noreply at wordpress.org
Tue Jul 20 20:18:08 UTC 2021
#53705: Plugin upgrade deletes files from other in-progress upgrades
-----------------------------+-----------------------------
Reporter: bpayton | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Upgrade/Install | Version: 5.8
Severity: normal | Keywords:
Focuses: |
-----------------------------+-----------------------------
If two plugin upgrades are requested at the same time, the later upgrade
can interfere with the earlier upgrade by deleting its source files while
the earlier upgrade is still in progress.
This can lead to either disappearing plugins or plugins with missing
files.
This is because Plugin_Upgrader::upgrade() calls WP_Upgrader::run() which
calls WP_Upgrader::unpack_package() [https://github.com/WordPress
/wordpress-develop/blob/0167d6dd502c0fe552071014f231dc0ee80e38c3/src/wp-
admin/includes/class-wp-upgrader.php#L778 here], and
WP_Upgrader::unpack_package() unconditionally deletes all files from the
wp-content/upgrade/ directory [https://github.com/WordPress/wordpress-
develop/blob/0167d6dd502c0fe552071014f231dc0ee80e38c3/src/wp-
admin/includes/class-wp-upgrader.php#L309-L317 here].
If plugin upgrade A is in progress with new plugin files under wp-
content/upgrade/, plugin upgrade B will delete them as part of unpacking
its zip file.
Plugin upgrade conflicts can cause a plugin to disappear with the
following sequence:
1. Plugin upgrade A downloads a zip for the new version
[https://github.com/WordPress/wordpress-
develop/blob/0167d6dd502c0fe552071014f231dc0ee80e38c3/src/wp-
admin/includes/class-wp-upgrader.php#L742 here]
2. Plugin upgrade A calls WP_Upgrader::unpack_package() to unpack the zip
to a unique subdirectory of wp-content/upgrade/
[https://github.com/WordPress/wordpress-
develop/blob/0167d6dd502c0fe552071014f231dc0ee80e38c3/src/wp-
admin/includes/class-wp-upgrader.php#L778 here]
3. Plugin upgrade A deletes the old version's plugin files
[https://github.com/WordPress/wordpress-
develop/blob/0167d6dd502c0fe552071014f231dc0ee80e38c3/src/wp-
admin/includes/class-wp-upgrader.php#L559 here]. This happens because
Plugin_Upgrader::upgrade() sets the clear_destination flag to true
[https://github.com/WordPress/wordpress-
develop/blob/0167d6dd502c0fe552071014f231dc0ee80e38c3/src/wp-
admin/includes/class-plugin-upgrader.php#L226 here].
4. Plugin upgrade B downloads a zip for its new version
[https://github.com/WordPress/wordpress-
develop/blob/0167d6dd502c0fe552071014f231dc0ee80e38c3/src/wp-
admin/includes/class-wp-upgrader.php#L742 here]
5. Plugin upgrade B calls WP_Upgrader::unpack_package() to unpack its zip
[https://github.com/WordPress/wordpress-
develop/blob/0167d6dd502c0fe552071014f231dc0ee80e38c3/src/wp-
admin/includes/class-wp-upgrader.php#L778 here], deleting all files of
plugin upgrade A from wp-content/upgrade/ [https://github.com/WordPress
/wordpress-develop/blob/0167d6dd502c0fe552071014f231dc0ee80e38c3/src/wp-
admin/includes/class-wp-upgrader.php#L309-L317 here]
5. Plugin upgrade A attempts to copy the new version into the plugins dir
[https://github.com/WordPress/wordpress-
develop/blob/0167d6dd502c0fe552071014f231dc0ee80e38c3/src/wp-
admin/includes/class-wp-upgrader.php#L594 here], but the new version's
files are completely gone.
6. Plugin upgrade A has already deleted its old version's files, and it
cannot copy the new files because they no longer exist.
7. Plugin upgrade A encounters an error, and its plugin has completely
disappeared.
This upgrade behavior can also lead to upgraded plugins with missing
files, following a progression similar to the one above. The only
difference is that, in case of missing plugin files, plugin upgrade A
succeeded in copying some files before plugin upgrade B deleted the rest
of them. Here, plugin upgrade A encounters an error, and the new plugin
version only has some of its files.
At Automattic, we encountered this when WordPress.com attempted to request
multiple, individual plugin updates for a standalone WP site all at once
via Jetpack. We encountered frequent, reproducible plugin update
corruption and tracked this down via error logging added to WP core
source.
NOTE: Based on this WP_Upgrader code, it might be that simultaneous, mixed
plugin and theme updates can also encounter this issue, but I have not
tested it.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/53705>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list