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

Unable to retrieve checkDiskSpace('/') result in AWS AppRunner #32

Open
mima3 opened this issue Jan 7, 2025 · 0 comments
Open

Unable to retrieve checkDiskSpace('/') result in AWS AppRunner #32

mima3 opened this issue Jan 7, 2025 · 0 comments

Comments

@mima3
Copy link

mima3 commented Jan 7, 2025

Thank you for providing such a great library.

I am reporting an issue where the result of checkDiskSpace('/') could not be retrieved properly in the following environment:

Execution Environment:

  • Machine: AWS AppRunner
  • Node version: Node.js 18

Cause:
When executed in virtualized environments like AWS AppRunner (or Docker-based environments), there are cases where the Filesystem field in the df output is omitted. This causes the library to fail to parse the command output properly.

Example df output:

Filesystem     1024-blocks  Used Available Capacity Mounted on
                    3355850    34   3179368       1% /
 tmpfs                65536     0     65536       0% /dev
 shm                 530264     0    530264       0% /dev/shm
 tmpfs               530264     0    530264       0% /sys/fs/cgroup
 /dev/vdd           3355850    34   3179368       1% /etc/hosts
 tmpfs               530264     0    530264       0% /sys/firmware
 tmpfs               530264     0    530264       0% /proc/scsi

Workaround:
To address this issue, I implemented the following workaround by avoiding reliance on the Filesystem field:

const { exec } = require('child_process');
const util = require('util');
const execPromise = util.promisify(exec);

async function checkDiskFreeSpace(path) {
  const { stdout, stderr } = await execPromise(`df -Pk -- ${path}`);
  if (stderr) {
    throw new Error(`Unexpected result from df command: ${stderr}`);
  }

  // Parse the output
  const parsedLines = stdout
    .split('\n') // Split lines
    .map(line => line.trim()) // Trim all lines
    .filter(line => line.length !== 0) // Remove empty lines
    .slice(1) // Remove header
    .map(line => line.split(/\s+(?=[\d/])/)); // Split columns by whitespace before numbers or "/"

  if (parsedLines.length === 0) {
    throw new Error(`Unexpected result from df command: ${stdout}`);
  }

  return parseInt(parsedLines[0][parsedLines[0].length - 3], 10) * 1024; // Convert to bytes
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant