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

Load needed (dynamic) dependencies for provisioners at creation time. #358

Merged
merged 3 commits into from Feb 12, 2014

Conversation

fnichol
Copy link
Contributor

@fnichol fnichol commented Feb 12, 2014

The need for this change was initated with #293 which runs every
instance action in a thread of execution, even in serial mode. The issue
is that on the Mac platform MRI Ruby 1.9 and 2.0 (not confirmed for
2.1), dynamic (i.e. native) code needs to be loaded in the main thread
otherwise causing a "Trace/BPT trap: 5" crash.

References:

For Berkshelf 2.0.x at least, there are multiple transitive dependencies
that could load native code, meaning that require 'berkshelf' could
very well lead to a VM crash if performed in a thread other than main.

This commit pushes library loading code ahead to Provisioner creation
time. In other words, by the time you have a Provisioner object
reference either Berkshelf, Librarian-Chef, or nothing has been required
(assuming a Chef provisioner).

A drawback to this approach is that these dynamic dependencies will be
eagerly loaded when Test Kitchen is booting for trivial CLI commands
such as kitchen list and kitchen diagnose. Further work is needed to
ensure that kitchen diagnose remains viable even in the face of a
failure to load these dependencies.

Finally, the loaded version of Berkshelf or Librarian-Chef will be
displayed to the user on INFO for converge action and DEBUG on code
loading for troubleshooting.

Closes #357

/cc @reset, @ivey, @sethvargo

The need for this change was initated with #293 which runs every
instance action in a thread of execution, even in serial mode. The issue
is that on the Mac platform MRI Ruby 1.9 and 2.0 (not confirmed for
2.1), dynamic (i.e. native) code needs to be loaded in the main thread
otherwise causing a "Trace/BPT trap: 5" crash.

References:

* http://stackoverflow.com/questions/9933969/matlab-ruby-gem-doesnt-work-when-called-from-thread#answer-12319780
* https://bugs.launchpad.net/sbcl/+bug/1014409

For Berkshelf 2.0.x at least, there are multiple transitive dependencies
that *could* load native code, meaning that `require 'berkshelf'` could
very well lead to a VM crash if performed in a thread other than main.

This commit pushes library loading code ahead to Provisioner creation
time. In other words, by the time you have a Provisioner object
reference either Berkshelf, Librarian-Chef, or nothing has been required
(assuming a Chef provisioner).

A drawback to this approach is that these dynamic dependencies will be
eagerly loaded when Test Kitchen is booting for trivial CLI commands
such as `kitchen list` and `kitchen diagnose`. Further work is needed to
ensure that `kitchen diagnose` remains viable even in the face of a
failure to load these dependencies.

Finally, the loaded version of Berkshelf or Librarian-Chef will be
displayed to the user on INFO for converge action and DEBUG on code
loading for troubleshooting.

Closes #357

/cc @reset, @ivey, @sethvargo
@sethvargo
Copy link
Contributor

👍

@reset
Copy link
Contributor

reset commented Feb 12, 2014

@fnichol makes perfect sense to me

In resolving #357 some code loading logic needed to be moved early in
an object's life meaning that an Instance (or a collaborator object)
could crash before `#diagnose` was callable.

A design goal for `kitchen diagnose` is that it not crash itself and to
provide some minimum useful information in a failure scenario.

This commit will return an error hash in the :instances and :loader keys
if an exception was raised.
@fnichol
Copy link
Contributor Author

fnichol commented Feb 12, 2014

Okay, kitchen diagnose is viable (enough) again in the face of a code loading error.

fnichol added a commit that referenced this pull request Feb 12, 2014
Load needed (dynamic) dependencies for provisioners at creation time.
@fnichol fnichol merged commit 12061d0 into master Feb 12, 2014
@fnichol fnichol deleted the provisioner-dep-loading branch February 12, 2014 20:28
@tmatilai
Copy link

Thanks a lot for the fast fix!

@fnichol
Copy link
Contributor Author

fnichol commented Feb 12, 2014

@tmatilai thank you for your help!

@test-kitchen test-kitchen locked and limited conversation to collaborators Nov 16, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test Kitchen 1.2.0 breaks Berkshelf 2.0 on (OS X)
4 participants