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

Handle all available bash output #193

Merged
merged 2 commits into from
Apr 14, 2017
Merged

Conversation

astraw38
Copy link

Should fix #192

@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 65.742% when pulling 9f4fae7 on astraw38:master into 9dbc52e on SimonKagstrom:master.

@codecov
Copy link

codecov bot commented Apr 12, 2017

Codecov Report

Merging #193 into master will increase coverage by 0.72%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #193      +/-   ##
==========================================
+ Coverage   65.73%   66.45%   +0.72%     
==========================================
  Files          53       54       +1     
  Lines        3315     3452     +137     
==========================================
+ Hits         2179     2294     +115     
- Misses       1136     1158      +22
Impacted Files Coverage Δ
src/engines/bash-engine.cc 86.59% <100%> (+0.04%) ⬆️
tests/recursive-ptrace/main.cc 83.82% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9dbc52e...9f4fae7. Read the comment docs.

@SimonKagstrom SimonKagstrom merged commit be37230 into SimonKagstrom:master Apr 14, 2017
@SimonKagstrom
Copy link
Owner

Merged, thanks!

mbland added a commit to mbland/kcov that referenced this pull request Jul 16, 2017
Pull SimonKagstrom#193 (written to resolve SimonKagstrom#192)
caused the mbland/go-script-bash Travis build to fail (which clones
SimonKagstrom/kcov each time) when kcov would hang after printing the
number of Bats test cases on Linux.

This change resolves the issue, but I am still working to write a
focused test case, both to understand the exact problem and to prevent a
regression.
mbland added a commit to mbland/kcov that referenced this pull request Jul 16, 2017
Pull SimonKagstrom#193 (written to resolve SimonKagstrom#192)
caused the mbland/go-script-bash Travis build to fail. That build clones
SimonKagstrom/kcov each time, and after that pull request, kcov began
hanging after printing the number of Bats test cases on Linux, e.g.:

  https://travis-ci.org/mbland/go-script-bash/jobs/246933167

This change resolves the issue by calling `file_readable` on standard
output before calling `getline`. However, I am still working to write a
focused test case, both to understand the exact problem and to prevent a
regression.
mbland added a commit to mbland/kcov that referenced this pull request Jul 20, 2017
Per the previous commit, this reproduces the problem caused by
SimonKagstrom#193 whereby using `getline` within the `handleStdout`
function in `src/engines/bash-engine.cc` would cause kcov to hang
indefinitely under certain conditions.

Though I don't have a perfect understanding yet, it appears that Bash
scripts that run for some amount of time and produce some amount of
standard output eventually end up blocking when trying to write. When
the parent `kcov` process subsequently blocks in `getline`, the child
process running the Bash script doesn't appear to be able to resume,
implying some sort of deadlock.

At any rate, the new bash_handle_all_output test case reliably
reproduces the failure and validates the fix from the previous commit.
It required adding a timeout capability to `KcovTestCase.do`.

I've also removed `@unittest.expectedFaulure` from `bash_subshell`, as
it isn't appear necessary and confirms that the behavior implemented by
SimonKagstrom#193 remains intact.
mbland added a commit to mbland/kcov that referenced this pull request Jul 20, 2017
Per the previous commit, this reproduces the problem caused by
SimonKagstrom#193 whereby multiple calls to `getline` within the
`handleStdout` function in `src/engines/bash-engine.cc` would cause kcov
to hang indefinitely.

The problem was due to the fact that the buffer to which Bash was
writing kcov tracing messages was getting full, so Bash would eventually
block on `write` calls to the `xtraceFd` (FD 782). After that point,
calls to `getline` to read the standard output from Bash would block as
well, creating a deadlock between the kcov parent and Bash child
processes.

Using a build of kcov from before the previous commit, running an
`strace` command similar to the following revealed that the xtraceFd (FD
782) buffer was getting full:

```
$ strace -f build/src/kcov coverage_dir tests/bash/handle-all-output.sh

[ ...snip ... ]

[pid 30363] <... read resumed> "550\n", 4096) = 4
[pid 30363] write(1, "550\n", 4550
)        = 4
[pid 30363] read(5,  <unfinished ...>
[pid 30366] <... write resumed> )       = 4
[pid 30366] write(782, "kcov@handle-all-output.sh@3@(( +"..., 38) = 38
[pid 30366] write(782, "kcov@handle-all-output.sh@3@(( i"..., 44) = 44
[pid 30366] write(782, "kcov@handle-all-output.sh@4@echo"..., 37
```

At this point the kcov (pid 30363) and Bash (pid 30366) processes hang
indefinitely.

The new `bash_handle_all_output` test case reliably reproduces the
failure and validates the fix from the previous commit. It required
adding a timeout capability to `KcovTestCase.do`.

I've also removed `@unittest.expectedFailure` from `bash_subshell`, as
it isn't necessary and confirms that the desired behavior implemented by
SimonKagstrom#193 remains intact.
SimonKagstrom referenced this pull request Jul 22, 2017
bash-engine: Check stdout readable before getline
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 this pull request may close these issues.

Missing some bash stdout with self-built binary
3 participants