quirkey/resque-status — Issue #53: update UUID dependency to latest version
Author: mkuipers
Created: 2012-01-27 16:24:10+00:00
State: open

A particularly frustrating issue I ran into with using UUID 2.0.2 was that it was trying to write a UUID to the state file and it ran into a conversion issue and could not recover from this error. I don't fully understand what caused this problem in the first place, but it occurred after updating resque-status to version 0.3.1.

The problem: UUID would try to write to the statefile in the initializer. It would pack the array of the mac addresses, the sequence and the time into the binary sequence according to the STATE_FILE_FORMAT template. Then, when actually calling io.write, it would get UndefinedConversionError. After that, it would have an empty state_file that it would try to read and unpack from, which would cause the second error.

The solution: In UUID 2.0.2, the write and read modes are always set to 'w' and 'r' in the open-lock methods. In later versions, it is 'wb' and 'rb' which allows the opened File to avoid the conversion error. A quick and dirty solution is to update the gem on your own machine so that all write and read modes include the 'b', however it would be best if we just updated the resque-status to use the latest version, 2.3.5.

For googling purposes if someone else runs into this issue, this is what the exceptions look like.

Initial problem:

Encoding::UndefinedConversionError: "\xDF" from ASCII-8BIT to UTF-8
from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/uuid-2.0.2/lib/uuid.rb:281:in `write'
from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/uuid-2.0.2/lib/uuid.rb:281:in `write_state'
from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/uuid-2.0.2/lib/uuid.rb:167:in `block in initialize'
from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/uuid-2.0.2/lib/uuid.rb:255:in `block in open_lock'
from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/uuid-2.0.2/lib/uuid.rb:252:in `open'
from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/uuid-2.0.2/lib/uuid.rb:252:in `open_lock'
from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/uuid-2.0.2/lib/uuid.rb:166:in `initialize'
from (irb):1:in `new'
from (irb):1
from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/railties-3.1.1/lib/rails/commands/console.rb:45:in `start'
from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/railties-3.1.1/lib/rails/commands/console.rb:8:in `start'
from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/railties-3.1.1/lib/rails/commands.rb:40:in `'
from script/rails:6:in `require'
from script/rails:6:in `

'

Then, if If the /var/tmp/ruby-uuid exists

NoMethodError: undefined method `unpack' for nil:NilClass
from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activesupport-3.1.1/lib/active_support/whiny_nil.rb:48:in `method_missing'
from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/uuid-2.0.2/lib/uuid.rb:265:in `read_state'
from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/uuid-2.0.2/lib/uuid.rb:224:in `block in next_sequence'
from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/uuid-2.0.2/lib/uuid.rb:255:in `block in open_lock'
from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/uuid-2.0.2/lib/uuid.rb:252:in `open'
from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/uuid-2.0.2/lib/uuid.rb:252:in `open_lock'
from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/uuid-2.0.2/lib/uuid.rb:223:in `next_sequence'
from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/uuid-2.0.2/lib/uuid.rb:160:in `initialize'
from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/uuid-2.0.2/lib/uuid.rb:112:in `new'
from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/uuid-2.0.2/lib/uuid.rb:112:in `generate'
from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/resque-status-0.3.1/lib/resque/plugins/status/hash.rb:152:in `generate_uuid'
from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/resque-status-0.3.1/lib/resque/plugins/status/hash.rb:15:in `create'
from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/resque-status-0.3.1/lib/resque/plugins/status.rb:85:in `enqueue'
from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/resque-status-0.3.1/lib/resque/plugins/status.rb:79:in `create'
from /home/developer/code/multi/vairifi2/app/helpers/Eraser.rb:33:in `async_erase'
from (irb):5
from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/railties-3.1.1/lib/rails/commands/console.rb:45:in `start'
from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/railties-3.1.1/lib/rails/commands/console.rb:8:in `start'
from /home/developer/.rvm/gems/ruby-1.9.2-p290@rails31/gems/railties-3.1.1/lib/rails/commands.rb:40:in `'
from script/rails:6:in `require'