Skip to content

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

@mima3

Description

@mima3

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions