Skip to content

Commit

Permalink
Avoid memory leak on uploading external instance files (#1088)
Browse files Browse the repository at this point in the history
## Done

- Avoid memory leak on uploading external instance files

Fixes #1087

## QA

1. Run the LXD-UI:
- On the demo server via the link posted by @webteam-app below. This is
only available for PRs created by collaborators of the repo. Ask
@mas-who or @edlerd for access.
- With a local copy of this branch, [build and run as described in the
docs](../CONTRIBUTING.md#setting-up-for-development).
2. Perform the following QA steps:
- upload a large external file on instance creation, monitor chromes
memory usage
  • Loading branch information
edlerd authored Feb 3, 2025
2 parents a4d4563 + ea97826 commit a15501c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/util/uploadExternalFormatFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ export const sendFileByWebSocket = (
onProgress(sentFileSize, file.size);
}

readNextFileChunk();
// setTimeout is used to prevent the stack from increasing and
// causing a memory leak on larger files,
// because readNextFileChunk is called recursively
setTimeout(readNextFileChunk, 0);
};

reader.onerror = (e) => {
Expand Down

0 comments on commit a15501c

Please sign in to comment.