s3:g_lock: remove a nested event loop, replacing the inner loop by select