Skip to content

Bug: JSON Arguments Added to Stream in executeCommand Function #790

@TheAlucardDev

Description

@TheAlucardDev

When using the executeCommand function to send commands to a Docker container, the command execution sometimes fails. Instead of the expected command being executed, the following JSON object appears in the stream:

{"stdin":true,"stream":true,"stdout":false,"hijack":true,"stderr":false}

This causes the command to be misinterpreted and the container to return an "Unknown command" error, rather than executing the intended command.

Steps to Reproduce:

  1. Call the executeCommand function with the appropriate container ID and a command.
  2. Observe that sometimes, instead of the intended command, the stream includes the JSON configuration as shown above.
export const executeCommand = async (
  containerId: string,
  cmd: string
): Promise<void> => {
  const container = docker.getContainer(containerId);

  const stream = await container.attach({
    stdin: true,
    stream: true,
    stdout: false,
    hijack: true,
    stderr: false,
  });

  stream.write(cmd + `\n`);
  stream.end();
};

example logs:

Logs: Example of what happens in the container log:

[09:49:04] [Server thread/INFO]: [Server] y
say y
[09:49:05] [Server thread/INFO]: [Server] y
say y
[09:49:06] [Server thread/INFO]: [Server] y
say y
[09:49:08] [Server thread/INFO]: [Server] y
say y
[09:49:08] [Server thread/INFO]: [Server] y
say y
[09:49:09] [Server thread/INFO]: [Server] y
{"stdin":true,"stream":true,"stdout":false,"hijack":true,"stderr":false}say y
[09:49:10] [Server thread/INFO]: Unknown command. Type "/help" for help.

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