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

Output marking is not thread-safe #4376

Open
ezyang opened this issue Mar 6, 2017 · 3 comments
Open

Output marking is not thread-safe #4376

ezyang opened this issue Mar 6, 2017 · 3 comments
Labels

Comments

@ezyang
Copy link
Contributor

ezyang commented Mar 6, 2017

I have observed under some conditions, Cabal will interleave stderr and stdout:

-----BEGIN CABAL OUTPUT-----
Downloading old-time-1.1.0.3...
[-Extracting /srv/code/haskell-pushbot/cabal-binaries/cabal-testsuite/PackageTests/NewBuild/T4375/cabal.dist/home/.cabal/packages/test-local-repo/old-locale/1.0.0.7/old-locale-1.0.0.7.tar.gz to /srv/code/haskell-pushbot/cabal-binaries/cabal-testsuite/PackageTests/NewBuild/T4375/cabal.dist/work/./dist/tmp/src-28346...-]
-----END CABAL OUTPUT-----
[-Updating old-locale.cabal with the latest revision from the index.-]
writing /srv/code/haskell-pushbot/cabal-binaries/cabal-testsuite/PackageTests/NewBuild/T4375/cabal.dist/home/.cabal/packages/test-local-repo/old-time/1.1.0.3/old-time-1.1.0.3.tar.gz
{+Extracting /srv/code/haskell-pushbot/cabal-binaries/cabal-testsuite/PackageTests/NewBuild/T4375/cabal.dist/home/.cabal/packages/test-local-repo/old-locale/1.0.0.7/old-locale-1.0.0.7.tar.gz to /srv/code/haskell-pushbot/cabal-binaries/cabal-testsuite/PackageTests/NewBuild/T4375/cabal.dist/work/./dist/tmp/src-28736...+}
{+Updating old-locale.cabal with the latest revision from the index.+}
creating dist

(in this case, the Downloading message is occurring in a separate thread onto stdout, while "Extracting..." is stderr). This is bad juju. Probably the correct way to fix this is to prefix the markers on every line so we never get confused, but then we have to make sure stderr doesn't get interleaved within a single line this way.

Related: #4357

@23Skidoo
Copy link
Member

23Skidoo commented Oct 15, 2017

If I read the hPutStr source correctly, this happens because in LineBuffering mode it acquires and releases the handle lock for each line it outputs. E.g. if you run hPutStr h "foo\nbar\n", it will acquire the lock, output "foo", then release and reacquire it, output "bar", and then release the lock again. So a simple way to work around this issue would probably be to use block buffering and flush the handle afterwards, or just prefix the marker on every line as the OP suggests.

@23Skidoo
Copy link
Member

Related: #4787.

@23Skidoo
Copy link
Member

or just prefix the marker on every line as the OP suggests.

If we do that, we should make sure that the notice v "foo\nbar" is handled correctly.

@jneira jneira added the type: testing Issues about project test suites label Mar 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants