Deal with race conditions when connect
Reimplement _flush retry mechanism