Skip to content

Commit

Permalink
🐛 Fix connection refused for ipv6 (#1463)
Browse files Browse the repository at this point in the history
* listen on dualstack for all gateways

* disable linting for this line
  • Loading branch information
itsjwala authored Dec 12, 2023
1 parent b28dc5d commit 3a1c2dd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/core/src/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export class Network {
this.#pending.delete(requestId);

// guard against redirects with the same requestId
// eslint-disable-next-line babel/no-unused-expressions
pending?.request.url === event.request.url &&
pending.request.method === event.request.method &&
await this._handleRequest(session, { ...pending, resourceType, interceptId });
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ export class Server extends http.Server {
});
}

// return host bind address - defaults to 0.0.0.0
// return host bind address - defaults to "::"
get host() {
return process.env.PERCY_SERVER_HOST || '0.0.0.0';
return process.env.PERCY_SERVER_HOST || '::';
}

// return the listening port or any default port
Expand All @@ -127,11 +127,11 @@ export class Server extends http.Server {
// return a string representation of the server address
address() {
let port = this.port;
// we need to specifically map 0.0.0.0 to localhost on windows as even though we
// can listen to all interfaces using 0.0.0.0 we cant make a request on 0.0.0.0 as
// we need to specifically map "::" to localhost on windows as even though we
// can listen to all interfaces using "::" we cant make a request on "::" as
// its an invalid ip address as per spec, but unix systems allow request to it and
// falls back to localhost
let host = `http://${this.host === '0.0.0.0' ? 'localhost' : this.host}`;
let host = `http://${this.host === '::' ? 'localhost' : this.host}`;
return port ? `${host}:${port}` : host;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/unit/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('Unit / Server', () => {

describe('#host', () => {
it('returns the host', async () => {
expect(server.host).toEqual('0.0.0.0');
expect(server.host).toEqual('::');
});

describe('with PERCY_SERVER_HOST set', () => {
Expand Down

0 comments on commit 3a1c2dd

Please sign in to comment.