Add lock when close all sockets