Fix closing sockets when api demands it.