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

Fix the problem with stdout buffering #36

Closed
LeonidVas opened this issue Apr 4, 2022 · 1 comment · Fixed by #57
Closed

Fix the problem with stdout buffering #36

LeonidVas opened this issue Apr 4, 2022 · 1 comment · Fixed by #57
Assignees

Comments

@LeonidVas
Copy link
Collaborator

When a new instance of tarantool is started in instance.go, by default the log will be written with block buffering. The stdbuf utility was used to change this behavior, but it is not installed on macOS by default. Needs to investigate the problem and implement a universal solution.

// Start starts the Instance with the specified parameters.
func (inst *Instance) Start() error {
  // By default (when using "glibc") "stdout" is line buffered when connected
  // to a TTY and block buffered (one page 4KB) when connected to a pipe / file.
  // This is not how we want to log work, so set "stdout" to line buffered mode
  // by using "stdbuf" utility. "strderr" is set to no-buffering by default.
  //
  // Several useful links:
  // https://www.pixelbeat.org/programming/stdio_buffering/
  // https://man7.org/linux/man-pages/man3/setbuf.3.html
  // https://github.com/coreutils/coreutils/blob/master/src/stdbuf.c
  inst.Cmd = exec.Command("stdbuf", "-o", "L",
    inst.tarantoolPath, "-e", instanceLauncher)
  inst.Cmd.Stdout = inst.logger.Writer()
  inst.Cmd.Stderr = inst.logger.Writer()
  inst.Cmd.Env = append(os.Environ(), "TT_CLI_INSTANCE="+inst.appPath)
  inst.Cmd.Env = append(inst.Cmd.Env,
    "TT_CLI_CONSOLE_SOCKET="+inst.consoleSocket)

  // Imitate the "tarantoolctl".
  inst.Cmd.Env = append(inst.Cmd.Env, "TARANTOOLCTL=true")
  // Set the sign that the program is running under "tt".
  inst.Cmd.Env = append(inst.Cmd.Env, "TT_CLI=true")

  // Start an Instance.
  if err := inst.Cmd.Start(); err != nil {
    return err
  }
  inst.done = false

  return nil
}

Note that the original problem may have been misunderstood by the author.

@Totktonada
Copy link
Member

Everything is okay with logs: they're written using pure write() (to stderr by default). Things are worse with print(), which is fwrite() / putchar() under the hood and is written to stdout if tarantool is not daemonized (using box.cfg({background = true})).

Please, clarify the issue.

0x501D added a commit that referenced this issue Apr 24, 2022
This patch enables linebuffering for stdout fstream.

Closes #36
0x501D added a commit that referenced this issue Apr 24, 2022
This patch enables linebuffering for stdout fstream.

Closes #36
0x501D added a commit that referenced this issue Apr 24, 2022
This patch enables linebuffering for stdout fstream.

Closes #36
0x501D added a commit that referenced this issue Apr 24, 2022
This patch enables linebuffering for stdout fstream.

Closes #36
LeonidVas pushed a commit that referenced this issue Apr 25, 2022
This patch enables linebuffering for stdout fstream.

Closes #36
@LeonidVas LeonidVas changed the title Fix the problem with the log write Fix the problem with stdout buffering Apr 27, 2022
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

Successfully merging a pull request may close this issue.

3 participants