Fixed random bug when writing a file to the socket channel. (thread race)