Make WordPress Core

Opened 6 years ago

Closed 4 years ago

Last modified 6 weeks ago

#52708 closed defect (bug) (fixed)

Loopback requests do not work on the local development environment

Reported by: johnbillion Owned by: johnbillion
Priority: normal Milestone: 6.1
Component: Build/Test Tools Version:
Severity: normal Keywords: has-patch
Cc: Focuses:

Description

Within the local development environment, loopback requests do not work because localhost:8889 does not resolve. This means the following are broken:

  • WP-Cron event spawning
  • Theme editor
  • Plugin editor
  • Multisite network upgrades

The error can be seen on the Site Health screen, by attempting to edit a PHP file with the theme or plugin editor, or by running npm run env:cli cron test. The error is:

cURL error 7: Failed to connect to localhost port 8889: Connection refused

Attachments (2)

52708-loopback-local.diff​ (291 bytes ) - added by sandrasanzdev 4 years ago.
Fix loopback requests on local environment
52708-loopback-local-3.diff​ (607 bytes ) - added by sandrasanzdev 4 years ago.
Enables loopback requests in php (site) and cli (tests) containers.

Download all attachments as: .zip

Change History (12)

#1 @swissspidy
6 years ago

  • Summary Loopback requestss do not work on the local development environment → Loopback requests do not work on the local development environment

@sandrasanzdev
4 years ago

Fix loopback requests on local environment

#2 @sandrasanzdev
4 years ago

  • Keywords has-patch added; needs-patch removed

#3 @SergeyBiryukov
4 years ago

  • Milestone Awaiting Review → 6.1

#4 @hasanuzzamanshamim
4 years ago

I tested with the provided patch by @sandrasanzdev on my local using

npm run env:cli cron test

But still getting the same issue.

Error: WP-Cron spawn failed with error:
cURL error 7: Failed to connect to localhost port 8889: Connection refused

@sandrasanzdev
4 years ago

Enables loopback requests in php (site) and cli (tests) containers.

#5 @sandrasanzdev
4 years ago

@hasanuzzamanshamim Thanks for testing :) I saw it fixed in the admin panel and forgot to run the test. Uploaded a fix in 52708-loopback-local-3.diff that passes the test too.

This ticket was mentioned in ​Slack in #core by sandrasanzdev. ​View the logs.


4 years ago

#7 @hasanuzzamanshamim
4 years ago

Thanks, @sandrasanzdev for the updated patch.
That patch works for me.

#8 @johnbillion
4 years ago

  • Owner set to johnbillion
  • Status new → reviewing

#9 @johnbillion
4 years ago

  • Resolution → fixed
  • Status reviewing → closed

In 53636:

Build/Test Tools: Enable loopback requests to work on the local development environment.

This maps localhost to the host machine so the requests get routed to the web server container.

Props sandrasanzdev, hasanuzzamanshamim

Fixes #52708

#10 @westonruter
6 weeks ago

In 64026:

Build/Test Tools: Fix loopback requests in the Docker environment.

In the local Docker environment, loopback requests failed with "cURL error 7: Could not connect to server". This broke WP-Cron spawning, the Site Health loopback and page cache tests, and the file editor's fatal error check. The web server runs in its own container, so inside the php and cli containers localhost is the container itself, where nothing listens on the published port. The localhost:host-gateway entry in extra_hosts did not help, since 127.0.0.1 is still resolved for localhost ahead of it.

A development-only mu-plugin now pins requests for the site's own Home or Site Address host to the Docker host gateway using CURLOPT_RESOLVE, and only in the local environment type. The php container installs it into wp-content/mu-plugins on startup. The host.docker.internal hostname is also mapped to the host gateway so that the gateway can also be resolved on Linux Docker Engine, which, unlike Docker Desktop, does not provide that name by default.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/12219.
Follow-up to r53636.

Props westonruter, wildworks, kirasong, apermo.
See #52708.
Fixes #65484.

Note: See TracTickets for help on using tickets.