fix race condition in sample