Opened 6 years ago
Last modified 2 weeks ago
#50228 new defect (bug)
Plugins can inadvertently trigger `wp_die()` infinite loop during site creation
| Reported by: | iandunn | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Networks and Sites | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description (last modified by )
Problem
This is one example of an execution path that leads to an infinite loop, but there are probably several others. It can happen to any callback that tries to query a new site's tables after the wp_insert_site action, and before the make_db_current_silent() call inside wp_initialize_site().
- Creating a new site in a Multisite network will eventually call
wp_initialize_site() - That calls
switch_to_blog() - A plugin could hook into the
switch_blog()action, and callget_locale(). - That calls
get_option(), which will trigger a MySQL error, because the tables don't exist. wpdb->print_error( )calls_default_wp_die_handler()- That calls
get_language_attributes(), which callsget_option() - The process repeats until PHP gives up.
( ! ) Fatal error: Uncaught Error: Maximum function nesting level of '256' reached, aborting! in wp-includes/class-wp-hook.php on line 196
It's not obvious to plugin developers that this kind of thing can happen, so I think Core should handle it gracefully.
Related: #49263
Potential solutions
wp_die()coule call a new_installing_wp_die_handler()whenis_installing()istrue. This could be a minimal version of_default_wp_die_handler(), where no database queries are made.
_default_wp_die_handler()could avoid callingget_language_attributes()whenis_installing()istrue.
- Something else?
Change History (3)
#2
@
6 years ago
- Component Upgrade/Install → Networks and Sites
- Description modified (diff)
- Focuses multisite removed
This ticket was mentioned in PR #12663 on WordPress/wordpress-develop by @realloc.
2 weeks ago
#3
- Keywords has-patch has-unit-tests added
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
https://core.trac.wordpress.org/ticket/50228
get_language_attributes()queries the database. During install (for example, midway through Multisite site creation, before the new site's tables exist), that query can re-trigger the database error that led towp_die()in the first place, loopingwp_die()until PHP's function nesting limit is reached. While installing, the handler must fall back to the already-computeddirattribute instead.