fixed timing problem with cleanup and io_flush() by using non-blocking