mirror of
https://github.com/n8n-io/n8n.git
synced 2026-09-24 23:22:38 +08:00
fix(core): Throw error when workflow is too big for webhook registration (#21860)
This commit is contained in:
@@ -87,6 +87,11 @@ export class CacheService extends TypedEmitter<CacheEvents> {
|
||||
return this.cache.kind === 'memory';
|
||||
}
|
||||
|
||||
async exists(key: string) {
|
||||
const ttl = await this.cache?.store.ttl(key);
|
||||
return !!ttl;
|
||||
}
|
||||
|
||||
// ----------------------------------
|
||||
// storing
|
||||
// ----------------------------------
|
||||
|
||||
@@ -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()', () => {
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user