diff --git a/.changeset/strong-taxis-give.md b/.changeset/strong-taxis-give.md new file mode 100644 index 000000000..f0dd2a56a --- /dev/null +++ b/.changeset/strong-taxis-give.md @@ -0,0 +1,5 @@ +--- +'@segment/analytics-core': patch +--- + +Fixes an issue introduced in v1.66.0 that caused analytics plugins to be removed from event processing if a destination threw an error while loading. diff --git a/packages/core/src/queue/__tests__/event-queue.test.ts b/packages/core/src/queue/__tests__/event-queue.test.ts index 98c984df5..f6f51adee 100644 --- a/packages/core/src/queue/__tests__/event-queue.test.ts +++ b/packages/core/src/queue/__tests__/event-queue.test.ts @@ -4,7 +4,7 @@ import { CoreAnalytics } from '../../analytics' import { pWhile } from '../../utils/p-while' import * as timer from '../../priority-queue/backoff' import { ContextCancelation } from '../../context' -import { CorePlugin } from '../../plugins' +import { CorePlugin, PluginType } from '../../plugins' import { pTimeout } from '../../callback' import { TestCtx, TestEventQueue } from '../../../test-helpers' @@ -609,6 +609,32 @@ describe('Flushing', () => { }) }) +describe('register', () => { + it('only filters out failed destinations after loading', async () => { + const eq = new TestEventQueue() + const goodDestinationPlugin = { + ...testPlugin, + name: 'good destination', + type: 'destination' as PluginType, + } + const failingPlugin = { + ...testPlugin, + name: 'failing', + type: 'destination' as PluginType, + + load: () => Promise.reject(new Error('I was born to throw')), + } + + const plugins = [testPlugin, goodDestinationPlugin, failingPlugin] + const promises = plugins.map((p) => eq.register(TestCtx.system(), p, ajs)) + await Promise.all(promises) + + expect(eq.plugins.length).toBe(2) + expect(eq.plugins).toContain(testPlugin) + expect(eq.plugins).toContain(goodDestinationPlugin) + }) +}) + describe('deregister', () => { it('remove plugin from plugins list', async () => { const eq = new TestEventQueue() diff --git a/packages/core/src/queue/event-queue.ts b/packages/core/src/queue/event-queue.ts index 4ca14d60a..0bcec05f9 100644 --- a/packages/core/src/queue/event-queue.ts +++ b/packages/core/src/queue/event-queue.ts @@ -61,7 +61,8 @@ export abstract class CoreEventQueue< error: err, }) - this.plugins = this.plugins.filter((p) => p === plugin) + // Filter out the failed plugin by excluding it from the list + this.plugins = this.plugins.filter((p) => p !== plugin) }) } else { await plugin.load(ctx, instance)