Fixed internal sockets not being closed