fix(core)!: Bind worker server to IPv4 (#11087)

This commit is contained in:
Iván Ovejero
2024-10-04 12:18:26 +02:00
committed by GitHub
parent d974b015d0
commit 6a12f0c5fa
6 changed files with 53 additions and 34 deletions

View File

@@ -5,7 +5,6 @@ import type { InstanceSettings } from 'n8n-core';
import { AssertionError } from 'node:assert';
import * as http from 'node:http';
import { PortTakenError } from '@/errors/port-taken.error';
import type { ExternalHooks } from '@/external-hooks';
import type { PrometheusMetricsService } from '@/metrics/prometheus-metrics.service';
import { bodyParser, rawBodyReader } from '@/middlewares';
@@ -34,7 +33,7 @@ describe('WorkerServer', () => {
beforeEach(() => {
globalConfig = mock<GlobalConfig>({
queue: {
health: { active: true, port: 5678 },
health: { active: true, port: 5678, address: '0.0.0.0' },
},
credentials: {
overwrite: { endpoint: '' },
@@ -59,8 +58,11 @@ describe('WorkerServer', () => {
).toThrowError(AssertionError);
});
it('should throw if port taken', async () => {
it('should exit if port taken', async () => {
const server = mock<http.Server>();
const procesExitSpy = jest
.spyOn(process, 'exit')
.mockImplementation(() => undefined as never);
jest.spyOn(http, 'createServer').mockReturnValue(server);
@@ -69,18 +71,19 @@ describe('WorkerServer', () => {
return server;
});
expect(
() =>
new WorkerServer(
globalConfig,
mock(),
mock(),
mock(),
externalHooks,
instanceSettings,
prometheusMetricsService,
),
).toThrowError(PortTakenError);
new WorkerServer(
globalConfig,
mock(),
mock(),
mock(),
externalHooks,
instanceSettings,
prometheusMetricsService,
);
expect(procesExitSpy).toHaveBeenCalledWith(1);
procesExitSpy.mockRestore();
});
});
@@ -89,8 +92,9 @@ describe('WorkerServer', () => {
const server = mock<http.Server>();
jest.spyOn(http, 'createServer').mockReturnValue(server);
server.listen.mockImplementation((_port, callback: () => void) => {
callback();
server.listen.mockImplementation((...args: unknown[]) => {
const callback = args.find((arg) => typeof arg === 'function');
if (callback) callback();
return server;
});
@@ -123,8 +127,9 @@ describe('WorkerServer', () => {
const server = mock<http.Server>();
jest.spyOn(http, 'createServer').mockReturnValue(server);
server.listen.mockImplementation((_port, callback: () => void) => {
callback();
server.listen.mockImplementation((...args: unknown[]) => {
const callback = args.find((arg) => typeof arg === 'function');
if (callback) callback();
return server;
});
@@ -177,8 +182,9 @@ describe('WorkerServer', () => {
prometheusMetricsService,
);
server.listen.mockImplementation((_port, callback: () => void) => {
callback();
server.listen.mockImplementation((...args: unknown[]) => {
const callback = args.find((arg) => typeof arg === 'function');
if (callback) callback();
return server;
});