fix bug when writing before connected