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

Troubles with demuxStream called from docker.run #159

Open
q0rban opened this issue Oct 11, 2023 · 1 comment
Open

Troubles with demuxStream called from docker.run #159

q0rban opened this issue Oct 11, 2023 · 1 comment

Comments

@q0rban
Copy link

q0rban commented Oct 11, 2023

I am trying to pass in a stdout and stderr array of streams from docker.run() in dockerode. Something like this:

    const stdout = new stream.PassThrough();
    const stderr = new stream.PassThrough();
    await docker.run(someimage, ['some', 'command'], [stdout, stderr]);

When I pass things in this way, nothing gets output to stdout or stderr streams. However, when I do the following, I do get the output I expect:

    const stdout = new stream.PassThrough();
    await docker.run(someimage, ['some', 'command'], stdout);

I've tracked this down to demuxStream in docker-modem, but I'm having trouble making sense of how it's supposed to work. In my testing, nextDataLength is always a very large integer that is much larger than the buffer.length, so the conditional statement that then writes to the streams is never called. I don't really understand buffers much, so I'm not sure if I'm just implementing something incorrectly, or if there is a bug.

I was wondering if it had something to do with endianess, as I am on an arm processor, but I had a coworker try on an intel processor and they had the same issue.

@q0rban
Copy link
Author

q0rban commented Oct 16, 2023

Banging my head on this some more, I decided to hack the code in demuxStream, specifically changing this:

    } else {
      if (buffer.length >= nextDataLength) {
        var content = bufferSlice(nextDataLength);
        if (nextDataType === 1) {
          stdout.write(content);
        } else {
          stderr.write(content);
        }
        nextDataType = null;
        // It's possible we got a "data" that contains multiple messages
        // Process the next one
        processData();
      }
    }

to this:

    } else {
      var content = bufferSlice(nextDataLength);
      if (nextDataType === 1) {
        stdout.write(content);
      } else {
        stderr.write(content);
      }
      nextDataType = null;
      if (buffer.length >= nextDataLength) {
        // It's possible we got a "data" that contains multiple messages
        // Process the next one
        processData();
      }
    }

With this change, I actually received output in stderr! The output I received was this:

pen 'tugboat': no such pool\r\n

If I run the same command using docker run ... the stderr is:

cannot open 'tugboat': no such pool

So the first 8 characters are missing from the stream with my hack. Does this give any clues as to what might be wrong?

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