Fixes race condition in resources

See #1378.
Followed the last option.