techdocs: fix buildLogTransport-related memory leak

Signed-off-by: zcmander <zcmander@gmail.com>
This commit is contained in:
zcmander
2023-10-20 10:56:58 +03:00
parent bae9015f2b
commit 48a61bfdca
3 changed files with 11 additions and 7 deletions
+5
View File
@@ -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`.
@@ -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!)) {
@@ -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.