Repository navigation
Closed
Description
This is a follow-up to #18 (comment)
We're seeing the following stacktrace when running Omnibus (another Chef product):
/home/jenkins/workspace/chef-build/architecture/x86_64/platform/el-5/project/chef/role/builder/omnibus/vendor/bundle/ruby/2.1.0/gems/json_pure-1.8.3/lib/json/pure/generator.rb:366:in `to_json': wrong argument type JSON::Pure::Generator::State (expected Data) (TypeError)
from /home/jenkins/workspace/chef-build/architecture/x86_64/platform/el-5/project/chef/role/builder/omnibus/vendor/bundle/ruby/2.1.0/gems/json_pure-1.8.3/lib/json/pure/generator.rb:366:in `block in json_transform'
from /home/jenkins/workspace/chef-build/architecture/x86_64/platform/el-5/project/chef/role/builder/omnibus/vendor/bundle/ruby/2.1.0/gems/json_pure-1.8.3/lib/json/pure/generator.rb:359:in `each'
from /home/jenkins/workspace/chef-build/architecture/x86_64/platform/el-5/project/chef/role/builder/omnibus/vendor/bundle/ruby/2.1.0/gems/json_pure-1.8.3/lib/json/pure/generator.rb:359:in `json_transform'
from /home/jenkins/workspace/chef-build/architecture/x86_64/platform/el-5/project/chef/role/builder/omnibus/vendor/bundle/ruby/2.1.0/gems/json_pure-1.8.3/lib/json/pure/generator.rb:341:in `to_json'
from /home/jenkins/workspace/chef-build/architecture/x86_64/platform/el-5/project/chef/role/builder/omnibus/vendor/bundle/ruby/2.1.0/gems/json_pure-1.8.3/lib/json/pure/generator.rb:293:in `generate'
from /home/jenkins/workspace/chef-build/architecture/x86_64/platform/el-5/project/chef/role/builder/omnibus/vendor/bundle/ruby/2.1.0/gems/json_pure-1.8.3/lib/json/common.rb:285:in `pretty_generate'
from /home/jenkins/workspace/chef-build/architecture/x86_64/platform/el-5/project/chef/role/builder/omnibus/vendor/bundle/ruby/2.1.0/bundler/gems/omnibus-961695bbc1b2/lib/omnibus/project.rb:1090:in `block in write_json_manifest'
from /home/jenkins/workspace/chef-build/architecture/x86_64/platform/el-5/project/chef/role/builder/omnibus/vendor/bundle/ruby/2.1.0/bundler/gems/omnibus-961695bbc1b2/lib/omnibus/project.rb:1089:in `open'
from /home/jenkins/workspace/chef-build/architecture/x86_64/platform/el-5/project/chef/role/builder/omnibus/vendor/bundle/ruby/2.1.0/bundler/gems/omnibus-961695bbc1b2/lib/omnibus/project.rb:1089:in `write_json_manifest'
from /home/jenkins/workspace/chef-build/architecture/x86_64/platform/el-5/project/chef/role/builder/omnibus/vendor/bundle/ruby/2.1.0/bundler/gems/omnibus-961695bbc1b2/lib/omnibus/project.rb:1080:in `build'
from /home/jenkins/workspace/chef-build/architecture/x86_64/platform/el-5/project/chef/role/builder/omnibus/vendor/bundle/ruby/2.1.0/bundler/gems/omnibus-961695bbc1b2/lib/omnibus/cli.rb:83:in `build'
from /home/jenkins/workspace/chef-build/architecture/x86_64/platform/el-5/project/chef/role/builder/omnibus/vendor/bundle/ruby/2.1.0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
from /home/jenkins/workspace/chef-build/architecture/x86_64/platform/el-5/project/chef/role/builder/omnibus/vendor/bundle/ruby/2.1.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
from /home/jenkins/workspace/chef-build/architecture/x86_64/platform/el-5/project/chef/role/builder/omnibus/vendor/bundle/ruby/2.1.0/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
from /home/jenkins/workspace/chef-build/architecture/x86_64/platform/el-5/project/chef/role/builder/omnibus/vendor/bundle/ruby/2.1.0/bundler/gems/omnibus-961695bbc1b2/lib/omnibus/cli/base.rb:33:in `dispatch'
from /home/jenkins/workspace/chef-build/architecture/x86_64/platform/el-5/project/chef/role/builder/omnibus/vendor/bundle/ruby/2.1.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
from /home/jenkins/workspace/chef-build/architecture/x86_64/platform/el-5/project/chef/role/builder/omnibus/vendor/bundle/ruby/2.1.0/bundler/gems/omnibus-961695bbc1b2/lib/omnibus/cli.rb:41:in `execute!'
from /home/jenkins/workspace/chef-build/architecture/x86_64/platform/el-5/project/chef/role/builder/omnibus/vendor/bundle/ruby/2.1.0/bundler/gems/omnibus-961695bbc1b2/bin/omnibus:16:in `<top (required)>'
from /home/jenkins/workspace/chef-build/architecture/x86_64/platform/el-5/project/chef/role/builder/omnibus/vendor/bundle/ruby/2.1.0/bin/omnibus:23:in `load'
from /home/jenkins/workspace/chef-build/architecture/x86_64/platform/el-5/project/chef/role/builder/omnibus/vendor/bundle/ruby/2.1.0/bin/omnibus:23:in `<main>'
Omnibus is calling JSON.pretty_generate and passing it a hash. I realize this is probably a bug in json_pure (maybe json_pure#198 or json_pure#186) but we are currently downgrading our jmespath version to prevent pulling in json_pure.
Metadata
Metadata
Assignees
Labels
No labels
Activity
tyler-ball commentedon Apr 1, 2016
@xeron We only saw this issue in our build system - can you provide a full stacktrace of where you are seeing this error using Chef?
xeron commentedon Apr 1, 2016
I don't have stacktrace right now because we've also locked
jmespathversion to 1.1.x and already killed bad hosts.This error was from our internal cookbook which calls
JSON.parse.lamont-granquist commentedon Apr 1, 2016
all that omnibus is doing is calling JSON.pretty_generate() with a hash.
https://github.com/chef/omnibus/blob/master/lib/omnibus/project.rb#L1090
its getting redirected to json_pure because that gem patches all its own methods in for the JSON gem.
most likely not a bug in this gem and instead a bug in the json_pure gem itself.
tyler-ball commentedon Apr 1, 2016
A confusing aspect is that we're only experiencing this issue on certain builders. On all those builders, we already have the
JSONgem installed - so the checks here and here should be loadingjson/extand notjson/pure.trevorrowe commentedon Apr 1, 2016
I have a meeting to run to, but I have been able to reproduce this, and I think I have a few thoughts on how we can avoid this. Sorry for the suspense!
tyler-ball commentedon Apr 1, 2016
@trevorrowe No worries - nothing like an exciting friday morning! 🎉 🚀 🎉
trevorrowe commentedon Apr 1, 2016
I put together a simple ruby script that reproduces the issue above. For this script to demonstrate the failure you need to be running Ruby 1.9.3, have jmespath 1.2.2 installed, and must not have version >= 1.8.1 of the json gem.
As shown above, if your application has
require 'json'prior torequire 'jmespath'then Ruby 1.9.3 will load your json native gem. After the native gem is loaded, jmespath will run the following code:The first attempt will fail, because the
#gemmethod call raises Gem::LoadError as json >= 1.8.1 is not available. It falls back on json_pure >= 1.8.1 which is available. This causes json_pure to mixin its modules on-top of those mixed in by json/ext. This is essentially the crux of ruby/json#186.A suitable workaround may be to have jmespath check to see if the JSON constant is defined first. If it is, it should not attempt to load json/ext or json/pure. This however may result in a version older than 1.8.1 being loaded. I suppose it could log a warning if this is the case. Having an older version will prevent it from correctly handling jmespath expressions that contains literal json values.
trevorrowe commentedon Apr 1, 2016
I modified my local copy of jmespath with the following:
The result of running jmespath with an older version of json prevents it from parsing json literals, for example:
This essentially means users that have loaded an older version of json will have a degraded experience using jmespath. To be fair, this is the same situation users found themselves in between 1.1.3 and 1.2.
Any thoughts on if the const defined check would be sufficient?
No longer loading json_pure if json has already been loaded.
trevorrowe commentedon Apr 1, 2016
The condition require has been merged in and released. This should hopefully prevents environments that have loaded json prior to loading jmespath from breaking json methods.