add a timeout to flush_pending()