Fix writing response if the write could not be finished in one rurun