diff --git a/.changeset/fluffy-colts-stop.md b/.changeset/fluffy-colts-stop.md new file mode 100644 index 0000000000..9f6c9aba3d --- /dev/null +++ b/.changeset/fluffy-colts-stop.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend-module-msgraph': patch +--- + +Fixed scheduler task remaining stuck in running state after pod termination by propagating AbortSignal into MicrosoftGraphOrgEntityProvider.read() diff --git a/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgEntityProvider.test.ts b/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgEntityProvider.test.ts index ddd91affda..786790bb2f 100644 --- a/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgEntityProvider.test.ts +++ b/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgEntityProvider.test.ts @@ -286,19 +286,24 @@ describe('MicrosoftGraphOrgEntityProvider', () => { readMicrosoftGraphOrgMocked.mockImplementationOnce( async (_client, _tenantId, options) => { if (options.signal?.aborted) { - throw new DOMException('The operation was aborted', 'AbortError'); + const error = new Error('The operation was aborted'); + error.name = 'AbortError'; + throw error; } return { users: [], groups: [] }; }, ); const taskDef = localTaskRunner.getTasks()[0]; - // Should resolve without throwing (the error is caught and logged internally) + // Should resolve without throwing (abort is caught and logged at debug level) await (taskDef.fn as (signal: AbortSignal) => Promise)( controller.signal, ); expect(entityProviderConnection.applyMutation).not.toHaveBeenCalled(); + expect(logger.debug).toHaveBeenCalledWith( + expect.stringContaining('refresh aborted due to shutdown'), + ); }); it('fail without schedule and scheduler', () => { diff --git a/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgEntityProvider.ts b/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgEntityProvider.ts index dca4fbef76..a6f2ee78d7 100644 --- a/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgEntityProvider.ts +++ b/plugins/catalog-backend-module-msgraph/src/processors/MicrosoftGraphOrgEntityProvider.ts @@ -397,6 +397,12 @@ export class MicrosoftGraphOrgEntityProvider implements EntityProvider { try { await this.read({ logger, signal: abortSignal }); } catch (error) { + if (error instanceof Error && error.name === 'AbortError') { + logger.debug( + `${this.getProviderName()} refresh aborted due to shutdown`, + ); + return; + } logger.error( `${this.getProviderName()} refresh failed, ${error}`, error,