Do inspect under container lock

It fixes some race conditions