This repository was archived by the owner on Apr 17, 2018. It is now read-only.
This repository was archived by the owner on Apr 17, 2018. It is now read-only.
DataMapper::Resource#run_once isn't thread-safe (and raises in remove_instance_variable) #286
Open
Description
run_once (https://github.com/datamapper/dm-core/blob/master/lib/dm-core/resource.rb#L1208-L1219) is not thread safe. Two callers can each check if the instance variable is set, find it to be false, then each set the instance variable in parallel. This is generally fine -- the method isn't intended to be a real mutex. The problem is that remove_instance_variable in the ensure block will blow up in this situation, since that method raises if the instance variable isn't currently defined.
Given what run_once is attempting to do, I think that simply ignoring errors from remove_instance_variable would be acceptable here, but wanted to get feedback before I submitted a PR with that change.
Thanks
Dave
Metadata
Metadata
Assignees
Labels
No labels