Skip to content

sandbox.stop() resolves with incomplete usage when shutdown is slow #350

Open

Description

@mattrossman

The SDK reference says sandbox.stop() resolves once the VM is fully stopped. When shutdown takes longer than ~15s though, it resolves early with status: "stopping" and no duration, activeCpuDurationMs, or networkTransfer. Calling stop() again returns them once the VM is down.

To reproduce on @vercel/sandbox@3.5.0:

import { Sandbox } from '@vercel/sandbox';

const sandbox = await Sandbox.create();
// Background process that ignores SIGTERM, so shutdown drags on
await sandbox.runCommand({
  cmd: 'bash',
  args: ['-c', "nohup bash -c 'trap \"\" TERM; sleep 40' >/dev/null 2>&1 &"],
  sudo: true,
});

for (const attempt of [1, 2]) {
  const start = Date.now();
  const { status, duration, activeCpuDurationMs, networkTransfer } = await sandbox.stop();
  console.log(attempt, `${Date.now() - start}ms`, JSON.stringify({ status, duration, activeCpuDurationMs, networkTransfer }));
}
await sandbox.delete();
1 15316ms {"status":"stopping"}
2 9226ms {"status":"stopped","duration":24578,"activeCpuDurationMs":1439,"networkTransfer":{"ingress":2771,"egress":1560}}

stop() is a single POST .../stop, so this looks API-side. Either stop() should wait until stopped, or the docs should say callers may need to call it again for final usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions