Do the clear under the main lock to avoid issues during TERM signal