fix race condition of select vs sample