Skip to content

Commit

Permalink
fixes issue where a destination plugin loading with an error caused o…
Browse files Browse the repository at this point in the history
…ther plugins to be removed (#1076)
  • Loading branch information
chrisradek authored Apr 24, 2024
1 parent 3c37def commit 1635e42
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/strong-taxis-give.md
Original file line number Diff line number Diff line change
@@ -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.
28 changes: 27 additions & 1 deletion packages/core/src/queue/__tests__/event-queue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/queue/event-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1635e42

Please sign in to comment.