Fixes race condition in resources

See #1378.