Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network access error stream_socket_client() ssl://... Host is unreachable #1047

Closed
tellyworth opened this issue Feb 23, 2024 · 3 comments · Fixed by #1048
Closed

Network access error stream_socket_client() ssl://... Host is unreachable #1047

tellyworth opened this issue Feb 23, 2024 · 3 comments · Fixed by #1048
Labels
[Feature] PHP.wasm [Type] Bug An existing feature does not function as intended

Comments

@tellyworth
Copy link

Some network access fails with a ssl stream error when running with kitchen-sink extensions and networking enabled.

For example, on the Dashboard page, the Events widget shows this error:

RSS Error: WP HTTP Error: stream_socket_client(): Unable to connect to ssl://wordpress.org:443 (Host is unreachable)

The browser never actually attempts to make this particular request; something is going wrong either in PHP or the WP HTTP code.

Steps to reproduce:

  1. Visit https://playground.wordpress.net/?networking=yes&php-extension-bundle=kitchen-sink&url=/wp-admin/
  2. Check the Events widget on the Dashboard page; you'll see a HTTP error similar to above.
  3. Check the Browser console and network tab; you'll see that no request was made to a wordpress.org RSS feed.

Expected: either the request should succeed, or the limitation should be documented if this is intended behaviour.

@dd32
Copy link
Member

dd32 commented Feb 23, 2024

After looking into this, from what I can tell, the http_api_transports filter doesn't appear to be in use anymore when using the normal wp_remote_* functions. I suspect it probably is if you call WP_HTTP_Curl::request() directly.

To me, it appears that it's no longer possible to disable the curl/streams handlers in Requests, I actually suspect it might not have been possible to disable them previously either; but because the curl and streams extensions weren't loaded, it was falling through to the Fetch handler.

I'm not seeing a filter in Requests to specify the transport to use either:
https://github.com/WordPress/wordpress-develop/blob/8448d06c49ade781ff6971054d79a84d90dc54ff/src/wp-includes/Requests/src/Requests.php#L225-L259

I suspect, the way forward is to get a filter into the Requests class; or have playground overwrite/modify the add_transport() function to allow us to load the Fetch handler ahead of others:
https://github.com/WordPress/wordpress-develop/blob/8448d06c49ade781ff6971054d79a84d90dc54ff/src/wp-includes/Requests/src/Requests.php#L205-L216

Example:
https://playground.wordpress.net/?php=8.0&networking=yes&plugin=debug-bar-console&plugin=debug-bar&wp=6.4&storage=none&php-extension-bundle=kitchen-sink&networking=yes
Screenshot 2024-02-23 at 11 00 30 am

@dd32
Copy link
Member

dd32 commented Feb 23, 2024

I think I found a workaround.. there is a generic filter that let's us change some of the basic Requests args, and it includes an option we can use to force a specific transport to be used:

add_action( 'requests-requests.before_request', function( $url, $headers, $data, $type, &$options ) {
	$options['transport'] = 'Wp_Http_Fetch';
}, 10, 5 );

Here's a request with, and without the above filter:

Screenshot 2024-02-23 at 11 28 35 am

@adamziel adamziel added [Type] Bug An existing feature does not function as intended [Feature] PHP.wasm labels Feb 29, 2024
@adamziel adamziel modified the milestone: Zero Crashes Feb 29, 2024
@adamziel
Copy link
Collaborator

Note I've merged a reflections-based fix around the same time this issue was reported, but I think @dd32's PR is a more elegant solution and I'd love to move forward with that one instead.

adamziel added a commit that referenced this issue Apr 16, 2024
As the 'http_api_transports' filter is deprecated and no longer actively
used, this filters the Requests library to always use the Fetch
transport.

## What problem is it solving?

When the kitchen sink is enabled (ie. streams extension) Requests is
using that for HTTP requests, rather than using the Fetch transport (and
does not automatically fallback to it).

## How is the problem addressed?

Filters the Requests internals to always use the transport.

## Testing Instructions

1. Load with kitchen sink
2. Observe failing requests, and no attempt to use Fetch
3. Apply Patch
4. Load with kitchen sink
5. Observe requests succeed (or fail with CORS issues via fetch).

Fixes #1047

---------

Co-authored-by: Adam Zieliński <adam@adamziel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] PHP.wasm [Type] Bug An existing feature does not function as intended
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants