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

Installing WordPress with localhost as absoluteURL fails with getaddrinfo ENOTFOUND localhost #203

Open
adamziel opened this issue Apr 14, 2023 · 1 comment
Labels
[Aspect] Networking [Aspect] Node.js Needs Triage [Type] Bug An existing feature does not function as intended

Comments

@adamziel
Copy link
Collaborator

Description

This code:

    const php = await PHP.load('7.4', {
        requestHandler: {
            documentRoot: '/wordpress',
            absoluteUrl: `http://localhost:1235/`,
        }
    })
    await php.request({
        url: '/wp-admin/install.php?step=2',
        method: 'POST',
        formData: {
            language: 'en',
            prefix: 'wp_',
            weblog_title: 'My WordPress Website',
            user_name: 'admin',
            admin_password: 'password',
            admin_password2: 'password',
            Submit: 'Install WordPress',
            pw_weak: '1',
            admin_email: '[email protected]'
        }
    });

Results in the following error:

Error: getaddrinfo ENOTFOUND localhost
at GetAddrInfoReqWrap.on lookup [as oncomplete] (node:dns: 107:26) {
errno: -3008,
code: 'ENOTFOUND*
syscall: 'getaddrinfo'
hostname: "Localhost'
}

Workaround

Use 127.0.0.1 instead of localhost

Why does it happen?

I'm not sure! My guess is it tries to resolve localhost using DNS resolution and is unaware of /etc/hosts. I think there's an emscripten function that handles getaddrinfo – there should be a way to hook into that and provide a custom resolution mechanism.

@adamziel
Copy link
Collaborator Author

adamziel commented Jun 2, 2023

This one needs testing – there is a chance this now works after a localhost resolution mechanism was added:

/**
* Emscripten resolves `localhost` to a random IP address. Let's
* make it always resolve to 127.0.0.1.
*/
DNS.address_map.addrs.localhost = '127.0.0.1';

@adamziel adamziel added this to the Zero Crashes milestone Feb 29, 2024
@adamziel adamziel moved this to Future work in Playground Board Jun 30, 2024
@adamziel adamziel removed this from the Zero Crashes milestone Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Aspect] Networking [Aspect] Node.js Needs Triage [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

1 participant