fix race condition by channel