diff --git a/.changeset/late-forks-fetch.md b/.changeset/late-forks-fetch.md new file mode 100644 index 0000000000..3ba15885e2 --- /dev/null +++ b/.changeset/late-forks-fetch.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-techdocs-backend': patch +--- + +Fix potential memory leak by not creating a build log transport if not given via `RouterOptions`. diff --git a/plugins/techdocs-backend/src/service/DocsSynchronizer.ts b/plugins/techdocs-backend/src/service/DocsSynchronizer.ts index fad915b068..7859b55e3f 100644 --- a/plugins/techdocs-backend/src/service/DocsSynchronizer.ts +++ b/plugins/techdocs-backend/src/service/DocsSynchronizer.ts @@ -48,7 +48,7 @@ export type DocsSynchronizerSyncOpts = { export class DocsSynchronizer { private readonly publisher: PublisherBase; private readonly logger: winston.Logger; - private readonly buildLogTransport: winston.transport; + private readonly buildLogTransport?: winston.transport; private readonly config: Config; private readonly scmIntegrations: ScmIntegrationRegistry; private readonly cache: TechDocsCache | undefined; @@ -64,7 +64,7 @@ export class DocsSynchronizer { }: { publisher: PublisherBase; logger: winston.Logger; - buildLogTransport: winston.transport; + buildLogTransport?: winston.transport; config: Config; scmIntegrations: ScmIntegrationRegistry; cache: TechDocsCache | undefined; @@ -109,7 +109,9 @@ export class DocsSynchronizer { }); taskLogger.add(new winston.transports.Stream({ stream: logStream })); - taskLogger.add(this.buildLogTransport); + if (this.buildLogTransport) { + taskLogger.add(this.buildLogTransport); + } // check if the last update check was too recent if (!shouldCheckForUpdate(entity.metadata.uid!)) { diff --git a/plugins/techdocs-backend/src/service/router.ts b/plugins/techdocs-backend/src/service/router.ts index 855d8b02f4..23b857b746 100644 --- a/plugins/techdocs-backend/src/service/router.ts +++ b/plugins/techdocs-backend/src/service/router.ts @@ -39,7 +39,6 @@ import { DocsBuildStrategy, } from './DocsBuildStrategy'; import * as winston from 'winston'; -import { PassThrough } from 'stream'; /** * Required dependencies for running TechDocs in the "out-of-the-box" @@ -113,9 +112,7 @@ export async function createRouter( options.catalogClient ?? new CatalogClient({ discoveryApi: discovery }); const docsBuildStrategy = options.docsBuildStrategy ?? DefaultDocsBuildStrategy.fromConfig(config); - const buildLogTransport = - options.buildLogTransport ?? - new winston.transports.Stream({ stream: new PassThrough() }); + const buildLogTransport = options.buildLogTransport; // Entities are cached to optimize the /static/docs request path, which can be called many times // when loading a single techdocs page.