fix socket write closing