Fix key gen race condition, fix #17289

fix #17289