javan / javan/whenever

Please require the Numeric after NumericSecond for scope visibility

Open
#812 0 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
8.9k
Forks
715
PR merge metrics
No merged PRs in 30d

Description

Hey there,

First of all, thank you for this amazing gem.

We have one problem related to our edge-case of working with Bundler Whenever and a background thread.

Due to the fact, that numeric.rb patches the Numeric, it expects the visibility of the NumericSeconds. What that means is, that in a rare case where you would have code running prior to loading whenever and you would require whenever, you end up with the following exception:

uninitialized constant Whenever

Would you be so kind (I can do it) and swap the loading order of those two classes?

ref https://github.com/javan/whenever/blob/master/lib/whenever.rb#L1
ref https://github.com/javan/whenever/blob/master/lib/whenever/numeric.rb#L3

repro (you need to start it couple of times and wait as it takes Ruby a while to jump with the require in between those executions and sometimes it will just hang forever):

Thread.new do
  while true
    begin
      1.respond_to?(:elo)
      sleep 0.00001
    rescue => e
      p e
    end
  end
end

sleep 0.1

require 'whenever'

end effect:

#<NameError: uninitialized constant Whenever>
#<NameError: uninitialized constant Whenever>
#<NameError: uninitialized constant Whenever>
#<NameError: uninitialized constant Whenever>
#<NameError: uninitialized constant Whenever>
#<NameError: uninitialized constant Whenever>
#<NameError: uninitialized constant Whenever>
#<NameError: uninitialized constant Whenever>
#<NameError: uninitialized constant Whenever>
#<NameError: uninitialized constant Whenever>
#<NameError: uninitialized constant Whenever>
#<NameError: uninitialized constant Whenever>
#<NameError: uninitialized constant Whenever>
#<NameError: uninitialized constant Whenever>
#<NameError: uninitialized constant Whenever>

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with lib/whenever.rb and lib/whenever/numeric.rb, which the issue identifies as the relevant loading points. Run the provided threaded reproduction several times to observe the intermittent NameError. Done means requiring whenever no longer produces the uninitialized constant Whenever error in that scenario.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.