Skip to content

RUBY-2869 Do not use mutexes in finalizers #2417

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

Merged
merged 6 commits into from
Feb 14, 2022

Conversation

comandeo
Copy link

@comandeo comandeo commented Feb 8, 2022

Finalizers are called from signal trap, so mutexes do not work there (see https://github.com/ruby/ruby/blob/master/thread_sync.c#L288).

kill_spec.db_name,
kill_spec.service_id
].join(MSG_SEPARATOR)
@pipe_write.puts(msg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call can block if the pipe is full. My understanding is there needs to be a thread that is constantly reading the pipe to ensure the writing side doesn't block indefinitely.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have, but Queue is thread safe, and according to its docs "The Queue class implements all the required locking semantics." So, we may encounter the same problem with queue. I'll do some testing, though. If it works, I would prefer queue over pipe here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to queue, seems to be safe.

@comandeo comandeo force-pushed the 2869-fix-mutexes-in-finalizers branch from d267a53 to a1fb68e Compare February 10, 2022 14:50
@comandeo comandeo requested a review from p-mongo February 11, 2022 09:10
@p-mongo
Copy link
Contributor

p-mongo commented Feb 11, 2022

I think it is more correct to use server addresses (Address instances) rather than seeds. The seeds may be missing port numbers.

@comandeo
Copy link
Author

I think it is more correct to use server addresses (Address instances) rather than seeds. The seeds may be missing port numbers.

Good point, changed accordingly.

@comandeo comandeo merged commit 3c675ea into mongodb:master Feb 14, 2022
@comandeo comandeo deleted the 2869-fix-mutexes-in-finalizers branch February 14, 2022 13:26
comandeo pushed a commit that referenced this pull request Feb 14, 2022
renatolond pushed a commit to apptweak/mongo-ruby-driver that referenced this pull request Jan 18, 2023
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

Successfully merging this pull request may close these issues.

4 participants