Coder Social home page Coder Social logo

Comments (4)

binocarlos avatar binocarlos commented on May 13, 2024

Ahhh this old chestnut :-)

So - me and Luke lost a day to this also, it turns out that attempting to write directly to os.Std{out,err} from a go-routine does very strange things with locking the process - we came across this when trying to close devstack after a test was running

Fixed this issue by removing TeeCommand and just printing the std{out,err} buffers - the command is now called RunCommandWithBuffer

It would be nice to know exactly why directly writing to os.Std{err,out} causes these deadlocks but let's bump that to a "deep dive to understand go concurrent stream writing" issue

from bacalhau.

binocarlos avatar binocarlos commented on May 13, 2024

So - it turns out that there is a more fundamental problem here: golang/go#23019

In summary:

  • exec a command
  • it spawns sub-commands which spawns sub-commands (bash job.sh -> grand-children)
  • stdout / stderr pipes from grand-children are linked to main go process
  • kill the top level child process

This will cause the deadlock because the grand-child is still thinking it's connected to the stdout/stderr pipes

The solution it seems is to always write to temporary files instead of os.Std{out,err} - this does not trigger the blocking code path....

So - let's update utils.go to handle running commands in this way so we don't get bitten by this again

from bacalhau.

lukemarsden avatar lukemarsden commented on May 13, 2024

This is how the Android team worked around the problem: https://go-review.googlesource.com/c/go/+/42271/3/misc/android/go_android_exec.go

We are doing something similar.

from bacalhau.

aronchick avatar aronchick commented on May 13, 2024

Fixed with this - a60f080

from bacalhau.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.