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

Frozen Array Error #52

Open
KhashayarDanesh opened this issue May 27, 2020 · 0 comments
Open

Frozen Array Error #52

KhashayarDanesh opened this issue May 27, 2020 · 0 comments

Comments

@KhashayarDanesh
Copy link

KhashayarDanesh commented May 27, 2020

I was deploying a cookbook which included recipes from chef-proxysql and there were some issues, as you see in the stack trace and the logs below:

Compiling Cookbooks...

================================================================================
Recipe Compile Error in /var/chef/cache/cookbooks/proxysql/libraries/base_service.rb
================================================================================

FrozenError
-----------
can't modify frozen Array

Cookbook Trace:
---------------
  /var/chef/cache/cookbooks/poise/files/halite_gem/poise/helpers/subresources/container.rb:220:in `included'
  /var/chef/cache/cookbooks/poise/files/halite_gem/poise/resource.rb:51:in `include'
  /var/chef/cache/cookbooks/poise/files/halite_gem/poise/resource.rb:51:in `poise_subresource_container'
  /var/chef/cache/cookbooks/poise/files/halite_gem/poise.rb:93:in `block in Poise'
  /var/chef/cache/cookbooks/proxysql/libraries/base_service.rb:8:in `include'
  /var/chef/cache/cookbooks/proxysql/libraries/base_service.rb:8:in `<class:ProxysqlBaseService>'
  /var/chef/cache/cookbooks/proxysql/libraries/base_service.rb:7:in `<class:Resource>'
  /var/chef/cache/cookbooks/proxysql/libraries/base_service.rb:6:in `<class:Chef>'
  /var/chef/cache/cookbooks/proxysql/libraries/base_service.rb:5:in `<top (required)>'

Relevant File Content:
----------------------
/var/chef/cache/cookbooks/poise/files/halite_gem/poise/helpers/subresources/container.rb:

213:                @container_default
214:              end
215:            end
216:
217:            def included(klass)
218:              super
219:              klass.extend(ClassMethods)
220>>             klass.const_get(:HIDDEN_IVARS) << :@subcontexts
221:              klass.const_get(:FORBIDDEN_IVARS) << :@subcontexts
222:            end
223:          end
224:
225:          extend ClassMethods
226:        end
227:      end
228:    end
229:  end

Additional information:
-----------------------
      Ruby objects are often frozen to prevent further modifications
      when they would negatively impact the process (e.g. values inside
      Ruby's ENV class) or to prevent polluting other objects when default
      values are passed by reference to many instances of an object (e.g.
      the empty Array as a Chef resource default, passed by reference
      to every instance of the resource).

      Chef uses Object#freeze to ensure the default values of properties
      inside Chef resources are not modified, so that when a new instance
      of a Chef resource is created, and Object#dup copies values by
      reference, the new resource is not receiving a default value that
      has been by a previous instance of that resource.

      Instead of modifying an object that contains a default value for all
      instances of a Chef resource, create a new object and assign it to
      the resource's parameter, e.g.:

      fruit_basket = resource(:fruit_basket, 'default')

      # BAD: modifies 'contents' object for all new fruit_basket instances
      fruit_basket.contents << 'apple'

      # GOOD: allocates new array only owned by this fruit_basket instance
      fruit_basket.contents %w(apple)


System Info:
------------
chef_version=14.14.29
platform=ubuntu
platform_version=18.04
ruby=ruby 2.5.7p206 (2019-10-01 revision 67816) [x86_64-linux]
program_name=chef-client worker: ppid=974;start=08:36:34;
executable=/opt/chef/bin/chef-client

As I looked this issue up, it appears that this was an issue with Poise 2.8.1 which is a dependency of this cookbook, as somebody asked the Poise maintainer in this issue and that issue was fixed in this commit which is a part of Poise 2.8.2 Release, so long story short, I will make a PR to bump the poise version in this cookbook's requirements to 2.8.2

Thanks.

KhashayarDanesh pushed a commit to KhashayarDanesh/chef-proxysql that referenced this issue May 27, 2020
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

No branches or pull requests

1 participant