fix deadlock/race condition