Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

nil.unpack issue #28

Open
gauravbhatti opened this issue Oct 3, 2012 · 17 comments
Open

nil.unpack issue #28

gauravbhatti opened this issue Oct 3, 2012 · 17 comments

Comments

@gauravbhatti
Copy link

I got this error
The error occurred while evaluating nil.unpack
I am using uuid-2.0.2 with rails2.3.4

@rumblinthebronx
Copy link

I got a similar issue while using UUID::generate on jruby-1.7.0-preview2

#<NoMethodError: undefined method unpack' for nil:NilClass> /home/developer/.rvm/gems/jruby-1.7.0.preview2/gems/uuid-2.3.6/lib/uuid.rb:376:inread_state'
/home/developer/.rvm/gems/jruby-1.7.0.preview2/gems/uuid-2.3.6/lib/uuid.rb:332:in next_sequence' /home/developer/.rvm/gems/jruby-1.7.0.preview2/gems/uuid-2.3.6/lib/uuid.rb:366:inopen_lock'
org/jruby/RubyIO.java:1180:in open' /home/developer/.rvm/gems/jruby-1.7.0.preview2/gems/uuid-2.3.6/lib/uuid.rb:363:inopen_lock'
/home/developer/.rvm/gems/jruby-1.7.0.preview2/gems/uuid-2.3.6/lib/uuid.rb:331:in next_sequence' /home/developer/.rvm/gems/jruby-1.7.0.preview2/gems/uuid-2.3.6/lib/uuid.rb:313:ingenerate'
org/jruby/ext/thread/Mutex.java:149:in synchronize' /home/developer/.rvm/gems/jruby-1.7.0.preview2/gems/uuid-2.3.6/lib/uuid.rb:297:ingenerate'
/home/developer/.rvm/gems/jruby-1.7.0.preview2/gems/uuid-2.3.6/lib/uuid.rb:127:in `generate'

@langhorst
Copy link
Contributor

I was unable to replicate this using jruby-1.7.2 (1.9.3p327), uuid-2.3.6, rails-3.2.11.

> rvm install jruby
> rvm use jruby
> rvm gemset create uuid
> rvm gemset use uuid
> git clone https://github.com/assaf/uuid.git
> cd uuid
> bundle install
> rake install
> rake test
> irb

Within irb:

> require 'uuid'
> UUID::generate
> require 'rails'
> UUID::generate
> 1000.times { puts UUID::generate }

No issues. I even tried requiring most of the gems available from gem list - no luck in replicating the issue. I wonder if this has something to do with the state file and your environment? Maybe try UUID::state_file = false to rule that out.

@udl
Copy link

udl commented May 16, 2013

I'm seeing the same issue with ruby ruby 1.9.3p385 when calling UUID.new.generate with gem version 2.3.6.

stacktrace:

.../shared/bundle/ruby/1.9.1/gems/uuid-2.3.6/lib/uuid.rb:376:in `read_state'
.../shared/bundle/ruby/1.9.1/gems/uuid-2.3.6/lib/uuid.rb:332:in `block in next_sequence'
.../shared/bundle/ruby/1.9.1/gems/uuid-2.3.6/lib/uuid.rb:366:in `block in open_lock'
.../shared/bundle/ruby/1.9.1/gems/uuid-2.3.6/lib/uuid.rb:363:in `open'
.../shared/bundle/ruby/1.9.1/gems/uuid-2.3.6/lib/uuid.rb:363:in `open_lock'
.../shared/bundle/ruby/1.9.1/gems/uuid-2.3.6/lib/uuid.rb:331:in `next_sequence'
.../shared/bundle/ruby/1.9.1/gems/uuid-2.3.6/lib/uuid.rb:262:in `initialize'

(replaced parts of the path by ...)

@zephyr-dev
Copy link

We are seeing this issue as well. We are using ruby 2.0.0-p0, rails 3.2.13. We encounter the error about once a day.

error: undefined method `unpack' for nil:NilClass
stack trace:

"/home/user/.rvm/gems/ruby-2.0.0-p0/gems/uuid-2.3.7/lib/uuid.rb:377:in `read_state'"
"/home/user/.rvm/gems/ruby-2.0.0-p0/gems/uuid-2.3.7/lib/uuid.rb:333:in `block in next_sequence'"
"/home/user/.rvm/gems/ruby-2.0.0-p0/gems/uuid-2.3.7/lib/uuid.rb:367:in `block in open_lock'"
"/home/user/.rvm/gems/ruby-2.0.0-p0/gems/uuid-2.3.7/lib/uuid.rb:364:in `open'"
"/home/user/.rvm/gems/ruby-2.0.0-p0/gems/uuid-2.3.7/lib/uuid.rb:364:in `open_lock'"
"/home/user/.rvm/gems/ruby-2.0.0-p0/gems/uuid-2.3.7/lib/uuid.rb:332:in `next_sequence'"
"/home/user/.rvm/gems/ruby-2.0.0-p0/gems/uuid-2.3.7/lib/uuid.rb:263:in `initialize'"
"/home/user/.rvm/gems/ruby-2.0.0-p0/gems/uuid-2.3.7/lib/uuid.rb:127:in `new'"
"/home/user/.rvm/gems/ruby-2.0.0-p0/gems/uuid-2.3.7/lib/uuid.rb:127:in `generate'"

Note that we have about 50 separate processes hitting this code at once.

@oleander
Copy link

oleander commented Sep 9, 2013

Same thing here.

[GEM_ROOT]/gems/uuid-2.3.7/lib/uuid.rb:377:in `read_state&#x27;
[GEM_ROOT]/gems/uuid-2.3.7/lib/uuid.rb:333:in `block in next_sequence&#x27;
[GEM_ROOT]/gems/uuid-2.3.7/lib/uuid.rb:367:in `block in open_lock&#x27;
[GEM_ROOT]/gems/uuid-2.3.7/lib/uuid.rb:364:in `open&#x27;
[GEM_ROOT]/gems/uuid-2.3.7/lib/uuid.rb:364:in `open_lock&#x27;
[GEM_ROOT]/gems/uuid-2.3.7/lib/uuid.rb:332:in `next_sequence&#x27;
[GEM_ROOT]/gems/uuid-2.3.7/lib/uuid.rb:263:in `initialize&#x27;
app/models/user.rb:26:in `new&#x27;
app/models/user.rb:26:in `block in &lt;class
[GEM_ROOT]/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:375:in `_run__2699327338686436562__initialize__callbacks&#x27;
[GEM_ROOT]/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:80:in `run_callbacks&#x27;
[GEM_ROOT]/gems/protected_attributes-1.0.3/lib/active_record/mass_assignment_security/core.rb:19:in `initialize&#x27;
[GEM_ROOT]/gems/activerecord-4.0.0/lib/active_record/inheritance.rb:27:in `new&#x27;
[GEM_ROOT]/gems/activerecord-4.0.0/lib/active_record/inheritance.rb:27:in `new&#x27;
[GEM_ROOT]/gems/protected_attributes-1.0.3/lib/active_record/mass_assignment_security/persistence.rb:45:in `create&#x27;
[GEM_ROOT]/gems/activerecord-4.0.0/lib/active_record/relation.rb:121:in `block in create&#x27;
[GEM_ROOT]/gems/activerecord-4.0.0/lib/active_record/relation.rb:270:in `scoping&#x27;
[GEM_ROOT]/gems/activerecord-4.0.0/lib/active_record/relation.rb:121:in `create&#x27;
[GEM_ROOT]/gems/activerecord-4.0.0/lib/active_record/relation.rb:133:in `first_or_create&#x27;
app/controllers/application_controller.rb:217:in `block in current_user&#x27;
app/controllers/application_controller.rb:222:in `call&#x27;
app/controllers/application_controller.rb:222:in `current_user&#x27;
[GEM_ROOT]/bundler/gems/paper_trail-98848bb9b2db/lib/paper_trail/frameworks/rails.rb:20:in `user_for_paper_trail&#x27;
[GEM_ROOT]/bundler/gems/paper_trail-98848bb9b2db/lib/paper_trail/frameworks/rails.rb:62:in `set_paper_trail_whodunnit&#x27;
[GEM_ROOT]/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:397:in `_run__1953005326139304363__process_action__callbacks&#x27;
[GEM_ROOT]/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:80:in `run_callbacks&#x27;
[GEM_ROOT]/gems/actionpack-4.0.0/lib/abstract_controller/callbacks.rb:17:in `process_action&#x27;
[GEM_ROOT]/gems/actionpack-4.0.0/lib/action_controller/metal/rescue.rb:29:in `process_action&#x27;
[GEM_ROOT]/gems/actionpack-4.0.0/lib/action_controller/metal/instrumentation.rb:31:in `block in process_action&#x27;
[GEM_ROOT]/gems/activesupport-4.0.0/lib/active_support/notifications.rb:159:in `block in instrument&#x27;
[GEM_ROOT]/gems/activesupport-4.0.0/lib/active_support/notifications/instrumenter.rb:20:in `instrument&#x27;
[GEM_ROOT]/gems/activesupport-4.0.0/lib/active_support/notifications.rb:159:in `instrument&#x27;
[GEM_ROOT]/gems/actionpack-4.0.0/lib/action_controller/metal/instrumentation.rb:30:in `process_action&#x27;
[GEM_ROOT]/gems/actionpack-4.0.0/lib/action_controller/metal/params_wrapper.rb:245:in `process_action&#x27;
[GEM_ROOT]/gems/activerecord-4.0.0/lib/active_record/railties/controller_runtime.rb:18:in `process_action&#x27;
[GEM_ROOT]/gems/actionpack-4.0.0/lib/abstract_controller/base.rb:136:in `process&#x27;
[GEM_ROOT]/gems/actionpack-4.0.0/lib/abstract_controller/rendering.rb:44:in `process&#x27;
[GEM_ROOT]/gems/actionpack-4.0.0/lib/action_controller/metal.rb:195:in `dispatch&#x27;
[GEM_ROOT]/gems/actionpack-4.0.0/lib/action_controller/metal/rack_delegation.rb:13:in `dispatch&#x27;
[GEM_ROOT]/gems/actionpack-4.0.0/lib/action_controller/metal.rb:231:in `block in action&#x27;
[GEM_ROOT]/gems/actionpack-4.0.0/lib/action_dispatch/routing/route_set.rb:80:in `call&#x27;
[GEM_ROOT]/gems/actionpack-4.0.0/lib/action_dispatch/routing/route_set.rb:80:in `dispatch&#x27;
[GEM_ROOT]/gems/actionpack-4.0.0/lib/action_dispatch/routing/route_set.rb:48:in `call&#x27;
[GEM_ROOT]/gems/actionpack-4.0.0/lib/action_dispatch/journey/router.rb:71:in `block in call&#x27;
[GEM_ROOT]/gems/actionpack-4.0.0/lib/action_dispatch/journey/router.rb:59:in `each&#x27;
[GEM_ROOT]/gems/actionpack-4.0.0/lib/action_dispatch/journey/router.rb:59:in `call&#x27;
[GEM_ROOT]/gems/actionpack-4.0.0/lib/action_dispatch/routing/route_set.rb:655:in `call&#x27;
[GEM_ROOT]/gems/omniauth-1.0.3/lib/omniauth/strategy.rb:168:in `call!&#x27;
[GEM_ROOT]/gems/omniauth-1.0.3/lib/omniauth/strategy.rb:148:in `call&#x27;
[GEM_ROOT]/gems/omniauth-1.0.3/lib/omniauth/strategy.rb:168:in `call!&#x27;
[GEM_ROOT]/gems/omniauth-1.0.3/lib/omniauth/strategy.rb:148:in `call&#x27;
[GEM_ROOT]/gems/omniauth-1.0.3/lib/omniauth/builder.rb:42:in `call&#x27;
[GEM_ROOT]/gems/request_store-1.0.5/lib/request_store/middleware.rb:9:in `call&#x27;
[GEM_ROOT]/gems/warden-1.2.3/lib/warden/manager.rb:35:in `block in call&#x27;
[GEM_ROOT]/gems/warden-1.2.3/lib/warden/manager.rb:34:in `catch&#x27;
[GEM_ROOT]/gems/warden-1.2.3/lib/warden/manager.rb:34:in `call&#x27;
[GEM_ROOT]/gems/rack-1.5.2/lib/rack/etag.rb:23:in `call&#x27;
[GEM_ROOT]/gems/rack-1.5.2/lib/rack/conditionalget.rb:25:in `call&#x27;
[GEM_ROOT]/gems/rack-1.5.2/lib/rack/head.rb:11:in `call&#x27;
[GEM_ROOT]/gems/actionpack-4.0.0/lib/action_dispatch/middleware/params_parser.rb:27:in `call&#x27;
[GEM_ROOT]/gems/actionpack-4.0.0/lib/action_dispatch/middleware/flash.rb:241:in `call&#x27;
[GEM_ROOT]/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:225:in `context&#x27;
[GEM_ROOT]/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:220:in `call&#x27;
[GEM_ROOT]/gems/actionpack-4.0.0/lib/action_dispatch/middleware/cookies.rb:486:in `call&#x27;
[GEM_ROOT]/gems/activerecord-4.0.0/lib/active_record/query_cache.rb:36:in `call&#x27;
[GEM_ROOT]/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call&#x27;
[GEM_ROOT]/gems/actionpack-4.0.0/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call&#x27;
[GEM_ROOT]/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:373:in `_run__2828308976458894793__call__callbacks&#x27;
[GEM_ROOT]/gems/activesupport-4.0.0/lib/active_support/callbacks.rb:80:in `run_callbacks&#x27;
[GEM_ROOT]/gems/actionpack-4.0.0/lib/action_dispatch/middleware/callbacks.rb:27:in `call&#x27;
[GEM_ROOT]/gems/actionpack-4.0.0/lib/action_dispatch/middleware/remote_ip.rb:76:in `call&#x27;
[GEM_ROOT]/gems/actionpack-4.0.0/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call&#x27;
[GEM_ROOT]/gems/actionpack-4.0.0/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call&#x27;
[GEM_ROOT]/gems/railties-4.0.0/lib/rails/rack/logger.rb:38:in `call_app&#x27;
[GEM_ROOT]/gems/railties-4.0.0/lib/rails/rack/logger.rb:21:in `block in call&#x27;
[GEM_ROOT]/gems/activesupport-4.0.0/lib/active_support/tagged_logging.rb:67:in `block in tagged&#x27;
[GEM_ROOT]/gems/activesupport-4.0.0/lib/active_support/tagged_logging.rb:25:in `tagged&#x27;
[GEM_ROOT]/gems/activesupport-4.0.0/lib/active_support/tagged_logging.rb:67:in `tagged&#x27;
[GEM_ROOT]/gems/railties-4.0.0/lib/rails/rack/logger.rb:21:in `call&#x27;
[GEM_ROOT]/gems/actionpack-4.0.0/lib/action_dispatch/middleware/request_id.rb:21:in `call&#x27;
[GEM_ROOT]/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call&#x27;
[GEM_ROOT]/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call&#x27;
[GEM_ROOT]/gems/rack-1.5.2/lib/rack/sendfile.rb:112:in `call&#x27;
[GEM_ROOT]/gems/railties-4.0.0/lib/rails/engine.rb:511:in `call&#x27;
[GEM_ROOT]/gems/railties-4.0.0/lib/rails/application.rb:97:in `call&#x27;
[GEM_ROOT]/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:30:in `method_missing&#x27;
[GEM_ROOT]/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:552:in `process_client&#x27;
[GEM_ROOT]/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:632:in `worker_loop&#x27;
[GEM_ROOT]/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:500:in `spawn_missing_workers&#x27;
[GEM_ROOT]/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:511:in `maintain_worker_count&#x27;
[GEM_ROOT]/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:277:in `join&#x27;
[GEM_ROOT]/gems/unicorn-4.6.3/bin/unicorn:126:in `&lt;top (required)&gt;&#x27;
[GEM_ROOT]/bin/unicorn:23:in `load&#x27;
[GEM_ROOT]/bin/unicorn:23:in `&lt;main&gt;&#x27;

I'm using Ruby 2.0.0

All other software versions can be seen above.

@Altonymous
Copy link

Any progress on this issue?

@mikelewis
Copy link

+1

@gtmax
Copy link

gtmax commented Mar 31, 2014

You can set state_file to false, but this might leave you with duplicated ids generated on the same machine, right?

Any drawbacks to simply retrying?

class UUID
  # Workaround for UUID gem failing sometimes on lock file access in a multiprocess environment
  # Which throws NoMethodError: undefined method `unpack' for nil:NilClass
  def generate_with_retry(*args)
    retries = 0
    begin
       generate_without_retry(*args)
    rescue StandardError => error
       retries += 1
       retry if retries < 3
       raise error, "[After trying #{retries} times] #{error.message}", error.backtrace
    end
  end
  alias_method_chain :generate, :retry # rails only, roll your own alias_method calls if outside rails
end

@slemiere
Copy link

I'm seeing this as well, @gtmax have you tried your code in a production environment ?

@gtmax
Copy link

gtmax commented Jul 10, 2014

@slemiere Yes, we are running with this code. However, from what I recall for some reason this still didn't solve the high-frequency concurrent multi-process UUID generation - and we realized that actually we didn't need a completely unique id there and switched to a cheaper SecureRandom.

@kazjote
Copy link

kazjote commented Sep 21, 2015

I can easily reproduce this problem on linux machine with:

require 'uuid'

20.times do
  fork { UUID.new while true }
end

Process.waitall

@oleander
Copy link

@kazjote I can confirm that's the case on OS X 10.10 as well.

@silasb
Copy link

silasb commented Oct 26, 2015

Just hit this on production as well.

@Altonymous
Copy link

We switched to SecureRandom as well.

@larryzhao
Copy link

I also have it with ruby-2.3.0 on Ubuntu 12.04/14.04. I rarely occurs but I am having it like 10 times a day.

/gems/uuid-2.3.8/lib/uuid.rb:377 in read_state
/gems/uuid-2.3.8/lib/uuid.rb:333 in block in next_sequence
/gems/uuid-2.3.8/lib/uuid.rb:367 in block in open_lock
/gems/uuid-2.3.8/lib/uuid.rb:364 in open
/gems/uuid-2.3.8/lib/uuid.rb:364 in open_lock
/gems/uuid-2.3.8/lib/uuid.rb:332 in next_sequence
/gems/uuid-2.3.8/lib/uuid.rb:263 in initialize

ninjabear pushed a commit to snowplow/snowplow-ruby-tracker that referenced this issue Aug 15, 2016
UUID gem randomly fails when generating UUIDs with high frequency.
See: assaf/uuid#28
@vineethvakeel
Copy link

We are seeing this issue when using uuid:2.3.9 with ruby 2.3.6 in our production environment. Has happened twice in the last 30 days.

Is the solution to use SecureRandom.uuid as shown in the commit above?

@silasb
Copy link

silasb commented Dec 31, 2021

@vineethvakeel we moved to SecureRandom.uuid a long time ago and that fixed many of our issues that we saw with this library.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests