Skip to content

Handle Open3 returning a nil status #93

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 2 commits into from
Feb 1, 2016
Merged

Handle Open3 returning a nil status #93

merged 2 commits into from
Feb 1, 2016

Conversation

pbrisbin
Copy link
Contributor

@pbrisbin pbrisbin commented Feb 1, 2016

Customers are experiencing this in production. It results in an engine error
output of:

NoMethodError: undefined method `success?' for nil:NilClass
    block in run at /usr/src/app/lib/cc/engine/analyzers/command_line_runner.rb:18

The included spec reproduces this error.

It's unclear what circumstances lead to this, but removing the NoMethodError
will at least let the engine's stderr come through, which we can then debug and
address thereafter.

/cc @codeclimate/review

I also added basic spec coverage before beginning, as its own commit.

yield out
else
raise ::CC::Engine::Analyzers::ParserError, "`#{command}` exited with code #{status.exitstatus}:\n#{err}"
exitstatus = status && status.exitstatus
raise ::CC::Engine::Analyzers::ParserError, "`#{command}` exited with code #{exitstatus}:\n#{err}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be exitstatus.inspect so that we get the nil explicitly printed?

@wfleming
Copy link
Contributor

wfleming commented Feb 1, 2016

FWIW I looked into this a bit a while back & from my notes, I believed this wasn't actually a failure case, but a race condition: the Open3 code internally uses Process.detach to get the wait thread, which returns nil if the pid given to it is not a valid pid. So my guess was that the parser ran & exited so quickly that by the time detach was called it didn't exist anymore. But it may very well have ran successfully.

My thinking was we should move away from open3 and use the same posix spawn gem patterns we do elsewhere (if it's not reliant on C bindings).

@pbrisbin
Copy link
Contributor Author

pbrisbin commented Feb 1, 2016

I'll happily move to POSIX::Spawn, will ping when ready for re-review.

@pbrisbin
Copy link
Contributor Author

pbrisbin commented Feb 1, 2016

Changed, squashed, and commit message updated. Ready for re-review.

@wfleming
Copy link
Contributor

wfleming commented Feb 1, 2016

LGTM.

@pbrisbin pbrisbin force-pushed the pb-nil-status branch 2 times, most recently from 3765e10 to ca5d187 Compare February 1, 2016 19:09
@pbrisbin
Copy link
Contributor Author

pbrisbin commented Feb 1, 2016

Had to go back to the original implementation because posix-spawn's not supported on JRuby.

Please see the last commit for a detailed message: ca5d187

@wfleming
Copy link
Contributor

wfleming commented Feb 1, 2016

I'm cool with it.

capture3 on JRuby will assign a pid variable as the result of spawn[1].
It then passes that to Process.detach[2]. If the process in question has
exited between these two statements, Process.detach will return nil.

It can't be determined then if the process had succeeded or not. Rather
than always assuming an error, we use a heuristic: if the output
produced parses as valid JSON, we should consider it successful.

[1]: https://github.com/jruby/jruby/blob/master/lib/ruby/stdlib/open3.rb#L200
[2]: https://github.com/jruby/jruby/blob/master/lib/ruby/stdlib/open3.rb#L201
pbrisbin added a commit that referenced this pull request Feb 1, 2016
Handle Open3 returning a nil status
@pbrisbin pbrisbin merged commit 97b6ba1 into master Feb 1, 2016
@pbrisbin pbrisbin deleted the pb-nil-status branch February 1, 2016 19:31
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