Fix race cond when closing logs