Skip to content

Use .capture3 not .popen3 for external parsers #60

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

Merged
merged 1 commit into from
Dec 28, 2015

Conversation

wfleming
Copy link
Contributor

In my testing, I believe this will fix the frequent timeouts we've seen
happen on specific files.

Like other issues we'd been seeing, these were actually
non-deterministic, they just happened to almost always fail. But I did
see them succeed occasionally: this may be partially why I didn't catch
this in testing before the prior release, since I ran it against some of
the same projects we saw failing. I just got lucky the first time
around.

What I saw locally was that sometimes the status thread given by .open3 would
be dead before it was asked for its value, and in those cases the call
seemed to succeed. If the thread was still alive when asked for its
value, it seemed to then hang indefinitely.

Looking at the code for .capture3, the biggest difference seems
to be the use of threads for capturing stdout/stderr. There's even a
warning in stdlib docs about deadlocking from not doing this! So I
think the previous implementation was effectively equivalent to a poor,
buggy implementation of .capture3, and we should just use the real one. It's
unclear to me if the older usage of IO.popen also suffered from this
behavior and we just happened to be swallowing it, or if the pipe buffer
behavior is a little different there.

I put together this test repo to stress the duplication engine across all languages. It reliably fails on master of this repo & succeeds on this branch.

Thoughts, @codeclimate/review ?

@gdiggs
Copy link
Contributor

gdiggs commented Dec 28, 2015

👍 awesome find. Seems good to me and the code is much cleaner. Do we have a graph that we can watch to measure the effectiveness of this? Maybe the error rate graph?

@gdiggs gdiggs closed this Dec 28, 2015
@gdiggs gdiggs reopened this Dec 28, 2015
In my testing, I believe this will fix the frequent timeouts we've seen
happen on specific files.

Like other issues we'd been seeing, these were actually
non-deterministic, they just happened to *almost* always fail. But I did
see them succeed occasionally: this may be partially why I didn't catch
this in testing before the prior release, since I ran it against some of
the same projects we saw failing. I just got lucky the first time
around.

What I saw locally was that sometimes the status thread given by `.open3` would
be dead before it was asked for its value, and in those cases the call
seemed to succeed. If the thread was still alive when asked for its
value, it seemed to then hang indefinitely.

Looking at the code for [`.capture3`][1], the biggest difference seems
to be the use of threads for capturing stdout/stderr. There's even a
warning in [stdlib docs about deadlocking from not doing this][2]! So I
think the previous implementation was effectively equivalent to a poor,
buggy implementation of `.capture3`, and we should just use the real one. It's
unclear to me if the older usage of `IO.popen` also suffered from this
behavior and we just happened to be swallowing it, or if the pipe buffer
behavior is a little different there.

[1]: https://github.com/jruby/jruby/blob/3dbb634f2764b24bca9e92ecd3d52d859cc0e847/lib/ruby/stdlib/open3.rb#L258-L274
[2]: http://ruby-doc.org/stdlib-2.2.3/libdoc/open3/rdoc/Open3.html#method-c-popen3
@wfleming wfleming force-pushed the will/command-line-running branch from 2ccab2e to 0982eeb Compare December 28, 2015 20:52
@jpignata
Copy link
Contributor

Looks promising. Cleaner, too!

wfleming added a commit that referenced this pull request Dec 28, 2015
Use .capture3 not .popen3 for external parsers
@wfleming wfleming merged commit 182ecf2 into master Dec 28, 2015
@wfleming wfleming deleted the will/command-line-running branch December 28, 2015 21:20
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.

3 participants