-
Notifications
You must be signed in to change notification settings - Fork 529
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
Prevent Hotswap#get
from acquiring a lock when there is no Resource
present
#3922
Conversation
Add comment Co-authored-by: Arman Bilge <armanbilge@gmail.com>
/** | ||
* 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. | ||
*/ |
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.
I think the original comment was okay, the lock is an implementation detail.
hs.get.useForever.start *> | ||
hs.swap(IO.sleep(1.second).toResource) *> |
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.
We should insert a sleep
between these two steps to be sure that the fiber start
s. 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.
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.
Agreed!
IO.sleep(2.seconds) *> | ||
hs.get.use_.timeout(1.second).void |
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.
I'm not sure if the rest tests anything meaningful.
Hotswap#get
from acquiring a lock when there is no Resource
present
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.
LGTM, thanks for all your work on this!
@armanbilge Thank you! I appreciate your patience :) |
Resolves #3802