diff --git a/.changeset/cuddly-dodos-allow.md b/.changeset/cuddly-dodos-allow.md new file mode 100644 index 0000000000..0901d630f1 --- /dev/null +++ b/.changeset/cuddly-dodos-allow.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-techdocs-node': patch +--- + +Update AWS file retrieval logic from storing file in buffer array to piping to res for better memory efficiency. diff --git a/plugins/techdocs-node/src/stages/publish/awsS3.ts b/plugins/techdocs-node/src/stages/publish/awsS3.ts index 395dee3688..bd8b96ee14 100644 --- a/plugins/techdocs-node/src/stages/publish/awsS3.ts +++ b/plugins/techdocs-node/src/stages/publish/awsS3.ts @@ -483,7 +483,18 @@ export class AwsS3Publish implements PublisherBase { res.setHeader(headerKey, headerValue); } - res.send(await streamToBuffer(resp.Body as Readable)); + (resp.Body as Readable) + .on('error', err => { + this.logger.warn( + `TechDocs S3 router failed to serve static files from bucket ${this.bucketName} at key ${filePath}: ${err.message}`, + ); + if (!res.headersSent) { + res.status(404).send('File Not Found'); + } else { + res.destroy(); + } + }) + .pipe(res); } catch (err) { assertError(err); this.logger.warn(