Skip to content

Dockerode attach hangs #18982

@pwilkin

Description

@pwilkin

What version of Bun is running?

1.2.8+adab0f64f

What platform is your computer?

Linux Ubuntu 24.10

What steps can reproduce the bug?

Create the following Jest test:

import Docker from 'dockerode';

describe("Dockerode", () => {
    it("should run a container", async () => {        
        const docker: Docker = new Docker();
        process.env.DEBUG = "dockerode:*";

        try {
            const container = await docker.createContainer({
                Image: 'python:3.12-bookworm',
                Cmd: ['/bin/bash', '-i'],
                Tty: true,
                AttachStdin: true,
                AttachStdout: true,
                AttachStderr: true,
                OpenStdin: true,
                StdinOnce: false,
            });
            await container.start();

            const logs = await container.logs({
                stdout: true,
                stderr: true,
                follow: false,
            });
            console.log(logs.toString());

            console.log("Boo");
            const stream = await container.attach({
                stream: false,
                stdin: true,
                hijack: true, // include hijack for a proper upgrade (even if it didnt help before)
            });
            console.log("Boo2");

            // When the "READY" marker has been printed by the shell, youll see it on STDOUT.
            stream.setEncoding('utf-8');
            stream.on('data', (chunk) => console.log('STDOUT:', chunk));

            // Now send your command:
            stream.write('echo "Hello, World!"\n');
        } catch (error) {
            console.error('Error running Docker IRF:', error);
        }
    });
});

The test hangs after "Boo":

ilintar@LinuksowaJaskinia:/mnt/win/h/aidev/ts-src$ bun test "/mnt/win/h/aidev/ts-src/test/basic.test.ts" -t "Dockerode"
bun test v1.2.8 (adab0f64)

test/basic.test.ts:

Boo
^C
ilintar@LinuksowaJaskinia:/mnt/win/h/aidev/ts-src$ bun test "/mnt/win/h/aidev/ts-src/test/basic.test.ts" -t "basic"^C
ilintar@LinuksowaJaskinia:/mnt/win/h/aidev/ts-src$ npx jest test/basic.test.ts 
  console.log


      at Object.<anonymous> (test/basic.test.ts:26:21)

  console.log
    Boo

      at Object.<anonymous> (test/basic.test.ts:28:21)

  console.log
    Boo2

      at Object.<anonymous> (test/basic.test.ts:34:21)

 PASS  test/basic.test.ts
  Dockerode
    ✓ should run a container (146 ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        2.808 s
Ran all test suites matching /test\/basic.test.ts/i.

What is the expected behavior?

The test should complete correctly writing "Boo" and "Boo2" on the console.

What do you see instead?

Test hangs on container.attach(...).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingbun:testSomething related to the `bun test` runnernode.jsCompatibility with Node.js APIs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions