fix race condition due to read locking instead of write locking