From fd08baf14159c50b5c3d8bf2df5cbcbc662f9919 Mon Sep 17 00:00:00 2001 From: yehorkardash Date: Tue, 9 Dec 2025 10:47:25 +0100 Subject: [PATCH] fix(core): Throw error when workflow is too big for webhook registration (#21860) --- packages/cli/src/services/cache/cache.service.ts | 5 +++++ .../test-webhook-registrations.service.test.ts | 13 +++++++++++++ .../test-webhook-registrations.service.ts | 15 ++++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/services/cache/cache.service.ts b/packages/cli/src/services/cache/cache.service.ts index 95fa1ace2b7..a61903075b9 100644 --- a/packages/cli/src/services/cache/cache.service.ts +++ b/packages/cli/src/services/cache/cache.service.ts @@ -87,6 +87,11 @@ export class CacheService extends TypedEmitter { return this.cache.kind === 'memory'; } + async exists(key: string) { + const ttl = await this.cache?.store.ttl(key); + return !!ttl; + } + // ---------------------------------- // storing // ---------------------------------- diff --git a/packages/cli/src/webhooks/__tests__/test-webhook-registrations.service.test.ts b/packages/cli/src/webhooks/__tests__/test-webhook-registrations.service.test.ts index dbc79aa7cdd..75352e11fa3 100644 --- a/packages/cli/src/webhooks/__tests__/test-webhook-registrations.service.test.ts +++ b/packages/cli/src/webhooks/__tests__/test-webhook-registrations.service.test.ts @@ -20,6 +20,11 @@ describe('TestWebhookRegistrationsService', () => { const webhookKey = 'GET|hello'; const cacheKey = 'test-webhooks'; + beforeEach(() => { + jest.resetAllMocks(); + cacheService.exists.mockResolvedValue(true); + }); + describe('register()', () => { test('should register a test webhook registration', async () => { await registrations.register(registration); @@ -32,6 +37,14 @@ describe('TestWebhookRegistrationsService', () => { expect(cacheService.expire).not.toHaveBeenCalled(); }); + + test('should throw an error if the registration fails', async () => { + cacheService.exists.mockResolvedValue(false); + + await expect(registrations.register(registration)).rejects.toThrow( + 'Test webhook registration failed: workflow is too big. Remove pinned data', + ); + }); }); describe('deregister()', () => { diff --git a/packages/cli/src/webhooks/test-webhook-registrations.service.ts b/packages/cli/src/webhooks/test-webhook-registrations.service.ts index cfdbc1143b4..13815f07dd2 100644 --- a/packages/cli/src/webhooks/test-webhook-registrations.service.ts +++ b/packages/cli/src/webhooks/test-webhook-registrations.service.ts @@ -1,6 +1,11 @@ import { Service } from '@n8n/di'; import { InstanceSettings } from 'n8n-core'; -import type { IWebhookData, IWorkflowBase, IDestinationNode } from 'n8n-workflow'; +import { + type IWebhookData, + type IWorkflowBase, + type IDestinationNode, + UserError, +} from 'n8n-workflow'; import { TEST_WEBHOOK_TIMEOUT, TEST_WEBHOOK_TIMEOUT_BUFFER } from '@/constants'; import { CacheService } from '@/services/cache/cache.service'; @@ -44,6 +49,14 @@ export class TestWebhookRegistrationsService { await this.cacheService.setHash(this.cacheKey, { [hashKey]: registration }); + const isCached = await this.cacheService.exists(this.cacheKey); + + if (!isCached) { + throw new UserError( + 'Test webhook registration failed: workflow is too big. Remove pinned data', + ); + } + if (this.instanceSettings.isSingleMain) return; /**