-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
Fix defining object finalizer in Ruby 3.1 to reference a UUID string #74
Fix defining object finalizer in Ruby 3.1 to reference a UUID string #74
Conversation
In Ruby 3.1.1, accessing callback_queue from a finalizer causes a "undefined local variable or method `callback_queue' for FiniteMachine::Observer:Class (NameError)", and callback_queue is never cleaned up. However, making the finalizer an instance method rather than a class method throws a warning about improper use of finalizers. The fix is borrowed from a Github issue found at https://github.com/appsignal/rdkafka-ruby/pull/160/files.
This just hit me also when trying to update an application to ruby 3.1. What do we need to be able to merge this? |
Hello 👋 - Re-asking @dup2 question: what do we need to be able to merge this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Vadim,
Thank you for the PR and for resolving this issue. Would you have time to look into the comments? I appreciate this is long overdue so hopefully, we can get this sorted for everyone.
Also, if you could add an entry in the changelog under the 'Fixed' heading with your name and handle that would be great. Please don't worry about the version, you can use '## unreleased' for now.
@piotrmurach Please let me know if there's anything else you need me to do to get this merged. Thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I've left a few more comments. The annoying thing is that this finalizer is only necessary when async callbacks are used. Otherwise, for the vast majority of cases, I believe it shouldn't be even defined. Eager to learn about what you think.
I've made a bit of refactoring to address your comments and after familiarizing myself further with how the |
@piotrmurach Is there anything we can do to get this merged and make this lib compatible with Ruby 3.1+. Happy to help in any way possible |
@abhishekjain16 You could help resolve the failing pipelines. That's probably the only thing that is still needed. |
lib/finite_machine/observer.rb
Outdated
|
||
@callback_queue = MessageQueue.new | ||
@object_id = SecureRandom.uuid | ||
ObjectSpace.define_finalizer(@object_id, cleanup_callback_queue) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vkononov This method needs to return @callback_queue
return @callback_queue if instance_variable_defined?(:@callback_queue)
@callback_queue = MessageQueue.new
@object_id = SecureRandom.uuid
ObjectSpace.define_finalizer(@object_id, cleanup_callback_queue)
@callback_queue
Add @callback_queue
to return from this method fixes pipeline
@vkononov https://github.com/piotrmurach/finite_machine/pull/74/files#r1285879315 This should fix the pipeline |
Thank you, @abhishekjain16. Can't believe I missed that. @piotrmurach, Could you run the pipeline and merge this code if the pipeline succeeds? |
Thanks for this. Are there any imminent plans to release a new version to RubyGems with this fix? |
@jimbali Thanks for your interest. I'm preparing a new release but cannot promise any timelines. |
Hi @piotrmurach, have you found any time to prepare a release for this yet? Any idea when that might be? Thanks |
Aw man, really sorry to hear that. Thanks for finding the time to sort this out. I've sponsored you a couple of coffees! |
@jimbali That's life and the show must go on. You didn't have to but thank you. Appreciate your kindness. 🙏 |
Describe the change
Fixes the "undefined local variable or method `callback_queue' for FiniteMachine::Observer:Class (NameError)" exception thrown in Ruby 3.1.1
Why are we doing this?
In Ruby 3.1.1, accessing callback_queue from a finalizer causes a "undefined local variable or method `callback_queue' for FiniteMachine::Observer:Class (NameError)", and callback_queue is never cleaned up. However, making the finalizer an instance method rather than a class method throws a warning about improper use of finalizers.
The fix is borrowed from a Github issue found at https://github.com/appsignal/rdkafka-ruby/pull/160/files.
Benefits
This library will become compatible with Ruby 3.1.1.
Drawbacks
None.
Requirements
master
branch?