Fix multi-thread issues by using reentrant lock for each connexion.