Fix data loss when closing the peer socket (#419)

fix #419