add write lock to avoid OOM