Skip to content

Commit 0aa4c6e

Browse files
committed
feat: Enhance uploadFile method to clean up abort signal event listener and prevent memory leaks
1 parent c389888 commit 0aa4c6e

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

frontend/src/common/services/storage/s3-storage-service.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,18 @@ export class S3StorageService {
155155
signal.addEventListener('abort', abortHandler);
156156
});
157157

158-
// Create a race between the upload and abortion
159-
await Promise.race([
160-
this.s3Client.send(new PutObjectCommand(uploadParams)),
161-
abortPromise
162-
]);
158+
try {
159+
// Create a race between the upload and abortion
160+
await Promise.race([
161+
this.s3Client.send(new PutObjectCommand(uploadParams)),
162+
abortPromise
163+
]);
164+
} finally {
165+
// Clean up the event listener to prevent memory leaks
166+
if (abortHandler && signal) {
167+
signal.removeEventListener('abort', abortHandler);
168+
}
169+
}
163170
} else {
164171
// Upload to S3 without abort capability
165172
await this.s3Client.send(new PutObjectCommand(uploadParams));

0 commit comments

Comments
 (0)