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

Prevent Hotswap#get from acquiring a lock when there is no Resource present #3922

Conversation

josgarmar28
Copy link
Contributor

Resolves #3802

Add comment

Co-authored-by: Arman Bilge <armanbilge@gmail.com>
@josgarmar28 josgarmar28 marked this pull request as ready for review January 4, 2024 10:47
Comment on lines 75 to 79
/**
* Gets the current resource, if it exists. The returned resource is guaranteed to be
* available for the duration of the returned resource.
* Acquires a shared lock to retrieve the current resource, if it exists. The returned
* resource is guaranteed to be available for its duration. The lock is released if the
* current resource does not exist.
*/
Copy link
Member

Choose a reason for hiding this comment

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

I think the original comment was okay, the lock is an implementation detail.

Comment on lines 172 to 173
hs.get.useForever.start *>
hs.swap(IO.sleep(1.second).toResource) *>
Copy link
Member

@armanbilge armanbilge Jan 8, 2024

Choose a reason for hiding this comment

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

We should insert a sleep between these two steps to be sure that the fiber starts. Also I think it's okay to just swap in a Resource.unit, basically we are checking that the swap succeeds and does not hang. If the get above had acquired a shared lock, then the swap would hang due to be unable to obtain an exclusive lock.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed!

Comment on lines 174 to 175
IO.sleep(2.seconds) *>
hs.get.use_.timeout(1.second).void
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if the rest tests anything meaningful.

@armanbilge armanbilge changed the title Prevent Hotswap#get from acquiring a lock when there is no Resource present Prevent Hotswap#get from acquiring a lock when there is no Resource present Jan 9, 2024
Copy link
Member

@armanbilge armanbilge left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for all your work on this!

@armanbilge armanbilge merged commit 4e1cac7 into typelevel:series/3.5.x Jan 9, 2024
28 of 32 checks passed
@josgarmar28
Copy link
Contributor Author

LGTM, thanks for all your work on this!

@armanbilge Thank you! I appreciate your patience :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants