Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: gzip before sending the os image to reduce frequency of timeouts #1120

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ RUN apt-get update && apt-get install --no-install-recommends -y \
vim \
build-essential \
make \
gzip \
python && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
Expand Down
8 changes: 6 additions & 2 deletions core/lib/common/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ module.exports = class Worker {
* @category helper
*/
async flash(imagePath) {

this.logger.log(`Gzipping image...`);
await exec(`gzip ${imagePath}`);
Copy link
Member

@vipulgupta2048 vipulgupta2048 Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding another OS dependency I was thinking if the entire problem is gzipping in the request causes a timeout then why not use the same logic to gzip out of the request something like

Create a temp file

pipeline(
  fs.createReadStream(imagePath),
  createGzip({ level: 6 }),
  tempFile
)
                         
await move(tempfile, imagePath) // https://stackoverflow.com/a/34499859 

This should also unlink/overrwite the image on imagePath


let attempt = 0;
await retry(
async () => {
Expand Down Expand Up @@ -187,9 +191,9 @@ module.exports = class Worker {
}
});

// append .gz extension as we zipped it above
pipeline(
fs.createReadStream(imagePath),
createGzip({ level: 6 }),
fs.createReadStream(`${imagePath}.gz`),
req,
);
});
Expand Down