Added session_write_close to prevent threading issues.