Project

General

Profile

Bug #16958

bytes: stack level too deep (SystemStackError)

Added by mikwat (Michael Watts) about 2 months ago. Updated 29 days ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:98771]

Description

Although I can't reliably reproduce this error, it appears that SecureRandom.base64 sometimes lands in an infinite loop. Here's the stack trace in our environment:

/opt/ui/vendor/ruby-2.7.1/lib/ruby/2.7.0/securerandom.rb:73:in `bytes': stack level too deep (SystemStackError)
from /opt/ui/vendor/ruby-2.7.1/lib/ruby/2.7.0/securerandom.rb:260:in `gen_random'
from /opt/ui/vendor/ruby-2.7.1/lib/ruby/2.7.0/securerandom.rb:73:in `bytes'
from /opt/ui/vendor/ruby-2.7.1/lib/ruby/2.7.0/securerandom.rb:260:in `gen_random'
from /opt/ui/vendor/ruby-2.7.1/lib/ruby/2.7.0/securerandom.rb:73:in `bytes'
from /opt/ui/vendor/ruby-2.7.1/lib/ruby/2.7.0/securerandom.rb:260:in `gen_random'
from /opt/ui/vendor/ruby-2.7.1/lib/ruby/2.7.0/securerandom.rb:73:in `bytes'
from /opt/ui/vendor/ruby-2.7.1/lib/ruby/2.7.0/securerandom.rb:260:in `gen_random'
from /opt/ui/vendor/ruby-2.7.1/lib/ruby/2.7.0/securerandom.rb:73:in `bytes'
... 10908 levels...
from /opt/ui/vendor/bundle/ruby/2.7.0/gems/mongo-2.12.1/lib/mongo/server/connection_pool/populator.rb:46:in `do_work'
from /opt/ui/vendor/bundle/ruby/2.7.0/gems/mongo-2.12.1/lib/mongo/background_thread.rb:101:in `block (2 levels) in start!'
from /opt/ui/vendor/bundle/ruby/2.7.0/gems/mongo-2.12.1/lib/mongo/background_thread.rb:99:in `catch'
from /opt/ui/vendor/bundle/ruby/2.7.0/gems/mongo-2.12.1/lib/mongo/background_thread.rb:99:in `block in start!'

SecureRandom.base64 was called from the mongo gem here:
https://github.com/mongodb/mongo-ruby-driver/blob/v2.12.1/lib/mongo/auth/scram/conversation.rb#L232

What I don't understand: from the stack trace it appears the definition of gen_random from the base module Random::Formatter is getting called instead of the definition from the sub module SecureRandom, resulting in an infinite loop.

Updated by jeremyevans0 (Jeremy Evans) about 2 months ago

  • Status changed from Open to Feedback

I can recreate this if I do SecureRandom.singleton_class.send(:remove_method, :gen_random) or SecureRandom.singleton_class.prepend Random::Formatter.dup. Is it possible something like that is happening in your environment? In either case, it isn't a bug in SecureRandom.

If you could put together a small example showing the problem without using any gems, that would be helpful for debugging.

#2

Updated by jeremyevans0 (Jeremy Evans) 29 days ago

  • Status changed from Feedback to Closed

Also available in: Atom PDF