:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(data-warehouse): stop the sync history poll after a source page closes (#129783)
Tom Owerse7c397751592
diff --git a/products/data_warehouse/frontend/scenes/SourceScene/tabs/dataWarehouseSourceSettingsLogic.test.ts b/products/data_warehouse/frontend/scenes/SourceScene/tabs/dataWarehouseSourceSettingsLogic.test.tsindex 51647a6ad133..eb43e2253d87 100644--- a/products/data_warehouse/frontend/scenes/SourceScene/tabs/dataWarehouseSourceSettingsLogic.test.ts+++ b/products/data_warehouse/frontend/scenes/SourceScene/tabs/dataWarehouseSourceSettingsLogic.test.ts@@ -1,4 +1,5 @@import { expectLogic } from 'kea-test-utils'+import posthog from 'posthog-js'import api from 'lib/api'import { LemonDialog } from 'lib/lemon-ui/LemonDialog'@@ -7,7 +8,7 @@ import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { resumeKeaLoadersErrors, silenceKeaLoadersErrors } from '~/initKea'import { initKeaTests } from '~/test/init'-import { ExternalDataSource, ExternalDataSourceSchema } from '~/types'+import { ExternalDataJob, ExternalDataSource, ExternalDataSourceSchema } from '~/types'import { sourceSceneLogic } from '../SourceScene'import { sourceSettingsLogic } from './sourceSettingsLogic'@@ -429,6 +430,62 @@ describe('sourceSettingsLogic', () => {})+ it.each([+ { name: 'jobs refresh resolves', action: 'loadJobs', settle: 'resolve' },+ { name: 'jobs refresh hits a gateway error', action: 'loadJobs', settle: 'reject' },+ { name: 'older jobs load resolves', action: 'loadMoreJobs', settle: 'resolve' },+ ] as const)('stops quietly when the source page closes before the $name', async ({ action, settle }) => {+ // Not assigned to `logic`, so afterEach does not unmount it a second time.+ const pageLogic = sourceSettingsLogic({ id: 'source-1' })+ pageLogic.mount()+ await expectLogic(pageLogic).toFinishAllListeners()++ jest.spyOn(api.externalDataSources, 'jobs').mockResolvedValueOnce([+ { id: 'job-2', created_at: '2026-01-02T00:00:00Z' } as any,+ ])+ pageLogic.actions.loadJobs()+ await expectLogic(pageLogic).toFinishAllListeners()++ let settleRequest: () => void = () => {}+ jest.spyOn(api.externalDataSources, 'jobs').mockReturnValueOnce(+ new Promise<ExternalDataJob[]>((resolve, reject) => {+ settleRequest = () =>+ settle === 'resolve'+ ? resolve([{ id: 'job-1', created_at: '2026-01-01T00:00:00Z' } as any])+ : reject(Object.assign(new Error('gateway'), { status: 504 }))+ })+ )+ const captureExceptionSpy = jest.spyOn(posthog, 'captureException')+ const consoleErrorSpy = jest.spyOn(console, 'error')++ pageLogic.actions[action]()+ pageLogic.unmount()+ settleRequest()+ await new Promise((resolve) => setTimeout(resolve, 0))++ expect(captureExceptionSpy).not.toHaveBeenCalled()+ expect(consoleErrorSpy).not.toHaveBeenCalled()+ })++ it('keeps a slow jobs load when another load starts while it is pending', async () => {+ logic = sourceSettingsLogic({ id: 'source-1' })+ logic.mount()+ await expectLogic(logic).toFinishAllListeners()++ let resolveSlowLoad: (jobs: ExternalDataJob[]) => void = () => {}+ jest.spyOn(api.externalDataSources, 'jobs')+ .mockReturnValueOnce(new Promise<ExternalDataJob[]>((resolve) => (resolveSlowLoad = resolve)))+ .mockReturnValueOnce(new Promise<ExternalDataJob[]>(() => {}))++ logic.actions.loadJobs()+ logic.actions.loadJobs()+ const slowJob = { id: 'job-1', created_at: '2026-01-01T00:00:00Z' } as ExternalDataJob++ await expectLogic(logic, () => resolveSlowLoad([slowJob])).toDispatchActions(['loadJobsSuccess'])++ expect(logic.values.jobs).toEqual([slowJob])+ })+it('re-throws non-transient errors from loadJobs so the failure path runs', async () => {logic = sourceSettingsLogic({ id: 'source-1' })logic.mount()diff --git a/products/data_warehouse/frontend/scenes/SourceScene/tabs/sourceSettingsLogic.ts b/products/data_warehouse/frontend/scenes/SourceScene/tabs/sourceSettingsLogic.tsindex 5be02877e35f..fc16b39f7558 100644--- a/products/data_warehouse/frontend/scenes/SourceScene/tabs/sourceSettingsLogic.ts+++ b/products/data_warehouse/frontend/scenes/SourceScene/tabs/sourceSettingsLogic.ts@@ -791,6 +791,12 @@ export const sourceSettingsLogic = kea<sourceSettingsLogicType>([// The API returns up to 50 jobs sorted by created_at desc, so this// will refresh the status of recent jobs (e.g. Running -> Completed).const freshJobs = await api.externalDataSources.jobs(values.sourceId, null, null, schemas)+ // The poll can outlive the source page, and reading values from the+ // unmounted logic throws. A breakpoint would also drop this load whenever+ // the 5s source refresh starts another one, so a slow query never lands.+ if (cache.disposables.isDisposed) {+ return []+ }// Merge fresh jobs with existing jobs, preferring the fresh dataconst jobsById = new Map(values.jobs.map((job) => [job.id, job]))@@ -806,6 +812,9 @@ export const sourceSettingsLogic = kea<sourceSettingsLogicType>([cache.jobsPollSoftFailureCount = 0return result} catch (error) {+ if (cache.disposables.isDisposed) {+ return []+ }// Gateway timeouts / transient upstream errors are expected when the jobs// query is slow. Swallow them here so the 5s poll doesn't become a source// of error-tracking noise; loadJobsSuccess reschedules with backoff.@@ -827,6 +836,9 @@ export const sourceSettingsLogic = kea<sourceSettingsLogicType>([null,schemas)+ if (cache.disposables.isDisposed) {+ return []+ }if (oldJobs.length === 0) {actions.setCanLoadMoreJobs(false)