mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-28 22:19:41 -08:00
fix(core): Fix serialization of circular json with task runner (#12288)
This commit is contained in:
parent
e0dc385f8b
commit
a99d726f42
|
@ -58,4 +58,28 @@ describe('TaskRunnerWsServer', () => {
|
||||||
expect(clearIntervalSpy).toHaveBeenCalled();
|
expect(clearIntervalSpy).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('sendMessage', () => {
|
||||||
|
it('should work with a message containing circular references', () => {
|
||||||
|
const server = new TaskRunnerWsServer(mock(), mock(), mock(), mock(), mock());
|
||||||
|
const ws = mock<WebSocket>();
|
||||||
|
server.runnerConnections.set('test-runner', ws);
|
||||||
|
|
||||||
|
const messageData: Record<string, unknown> = {};
|
||||||
|
messageData.circular = messageData;
|
||||||
|
|
||||||
|
expect(() =>
|
||||||
|
server.sendMessage('test-runner', {
|
||||||
|
type: 'broker:taskdataresponse',
|
||||||
|
taskId: 'taskId',
|
||||||
|
requestId: 'requestId',
|
||||||
|
data: messageData,
|
||||||
|
}),
|
||||||
|
).not.toThrow();
|
||||||
|
|
||||||
|
expect(ws.send).toHaveBeenCalledWith(
|
||||||
|
'{"type":"broker:taskdataresponse","taskId":"taskId","requestId":"requestId","data":{"circular":"[Circular Reference]"}}',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { TaskRunnersConfig } from '@n8n/config';
|
import { TaskRunnersConfig } from '@n8n/config';
|
||||||
import type { BrokerMessage, RunnerMessage } from '@n8n/task-runner';
|
import type { BrokerMessage, RunnerMessage } from '@n8n/task-runner';
|
||||||
import { ApplicationError } from 'n8n-workflow';
|
import { ApplicationError, jsonStringify } from 'n8n-workflow';
|
||||||
import { Service } from 'typedi';
|
import { Service } from 'typedi';
|
||||||
import type WebSocket from 'ws';
|
import type WebSocket from 'ws';
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ export class TaskRunnerWsServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMessage(id: TaskRunner['id'], message: BrokerMessage.ToRunner.All) {
|
sendMessage(id: TaskRunner['id'], message: BrokerMessage.ToRunner.All) {
|
||||||
this.runnerConnections.get(id)?.send(JSON.stringify(message));
|
this.runnerConnections.get(id)?.send(jsonStringify(message, { replaceCircularRefs: true }));
|
||||||
}
|
}
|
||||||
|
|
||||||
add(id: TaskRunner['id'], connection: WebSocket) {
|
add(id: TaskRunner['id'], connection: WebSocket) {
|
||||||
|
|
Loading…
Reference in a new issue