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

undefined method 'status' for nil:NilClass (NoMethodError) in runner.rb #14

Open
charliebabbitt1988 opened this issue Nov 6, 2023 · 1 comment

Comments

@charliebabbitt1988
Copy link

The error message, (undefined method 'status' for nil:NilClass (NoMethodError)) indicates that the Ruby program attempted to call the status method on an object that was expected to be an instance of a class, but at runtime, this object was actually nil (Ruby's equivalent of null in other programming languages). This situation is commonly known as a "null pointer exception" in other programming languages.

./blue_hydra/lib/blue_hydra/runner.rb:268:in 'block in stop': This indicates that the error occurred in the file runner.rb on line 268, inside a method called stop.
The block in stop part suggests that the problematic code is within a block (likely an each loop or similar iteration) within the stop method.
The actual error occurred because the program tried to call the status method on an object that was unexpectedly nil.

This issue might be caused by:

A bug in the code where an object is not properly instantiated or is set to nil under certain conditions.
The program might expect a certain service, process, or resource to be available and represented by an object, but it's not present, leading to the nil value.
The program could be in an inconsistent state due to an earlier error, exception, or unexpected behavior, leading to variables being set to nil.

The extracted code from the runner.rb file around line 268 provides insight into the issue. Here's the relevant section:

stop_condition = Proc.new do
  [nil, false].include?(result_thread.status) ||
  [nil, false].include?(parser_thread.status) ||
  self.result_queue.empty?
end

# clear queue...
until stop_condition.call
  unless self.cui_thread
    BlueHydra.logger.info("Remaining queue depth: #{self.result_queue.length}")
    sleep 5
  else

The error seems to be related to a call to the status method on the result_thread or parser_thread objects. The stop_condition Proc (a kind of lambda or anonymous function in Ruby) checks the status of result_thread and parser_thread, expecting these objects to be threads.

The error undefined method 'status' for nil:NilClass suggests that either result_thread or parser_thread is nil at the time this code is executed. Since threads are expected to be present here, one possible cause for this error could be:

The threads were never started properly due to a condition not being met or an exception being thrown before their instantiation.
The threads could have been terminated or killed elsewhere in the code, leading to their variables being set to nil.
The initialization of these threads is conditional, and the conditions for their initialization were not satisfied.

To prevent such errors, the code should check if these objects are nil before calling methods on them. This can be done with simple conditional checks.

Given the snippet above, it seems that the error could be mitigated by modifying the stop_condition Proc to be more defensive, for example:

stop_condition = Proc.new do
  [nil, false].include?(result_thread&.status) ||
  [nil, false].include?(parser_thread&.status) ||
  self.result_queue.empty?
end

Please note that the current version of Blue Hydra very rarely experiences this issue, but it can and does occur randomly and occasionally.

@ZeroChaos-
Copy link
Owner

I'd love to see the whole log that includes the error. Your detailed description is great but it's probably more important to fix the error that leads to this issue than it is to fix this code. Please include the whole error log if you can get this to happen again.

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

2 participants