Throw IOException when writing closed socket.

@marco-c The root cause of the previous test failing is that the socket is closed before the data in the buffer is fetched, this bug is triggered right after we use Native.create and Promise.