FAKE icon indicating copy to clipboard operation
FAKE copied to clipboard

races in console trace while running Shell.Exec

Open zhongjn opened this issue 3 years ago • 3 comments

Description

While running commands with Shell.Exec, output from stdout or stderr gets wrong.

Repro steps

  1. Step A Prepare a bash script err.sh:
>&2 echo err1 # writes to stderr
>&1 echo out1 # writes to stdout
>&2 echo err2
>&1 echo out2
sleep 1
  1. Step B Use Shell.Exec to execute the bash script. I executed the script multiple times here to make the problem more obvious.
Shell.Exec("bash", "scripts/err.sh") |> ignore
Shell.Exec("bash", "scripts/err.sh") |> ignore
Shell.Exec("bash", "scripts/err.sh") |> ignore

Expected behavior

Output are colored accordingly. Lines are not messed up.

Actual behavior

image

Known workarounds

Please provide a description of any known workarounds.

Related information

  • Operating system: Ubuntu 20.04
  • .NET Runtime: 6.0
  • Version of FAKE: latest

zhongjn avatar Feb 04 '22 11:02 zhongjn

Welcome to the FAKE community! Thank you so much for creating your first issue and therefore improving the project!

github-actions[bot] avatar Feb 04 '22 12:02 github-actions[bot]

The root cause shold be:

  1. While running the command, callbacks are executed in different threads:

https://github.com/fsprojects/FAKE/blob/79aa1273d0311595bd404be5721d994301774552/src/app/Fake.Core.Process/Process.fs#L843-L850

  1. Trace is not thread-safe, since ConsoleTraceListener is not thread-safe:

https://github.com/fsprojects/FAKE/blob/79aa1273d0311595bd404be5721d994301774552/src/app/Fake.Core.Trace/TraceListener.fs#L273-L308

Could we simply make ConsoleTraceListener thread-safe to fix this problem? If so, i could make a PR to fix this.

zhongjn avatar Feb 04 '22 12:02 zhongjn

Thanks for reporting. Can you please use the create process API instead? Since the asyncShellExex is marked with an obsolete attribute. https://github.com/fsprojects/FAKE/blob/79aa1273d0311595bd404be5721d994301774552/src/app/Fake.Core.Process/Process.fs#L826-L829

yazeedobaid avatar Feb 07 '22 08:02 yazeedobaid