On master (7eed413e72a236b6f1475a198f7063fd24929e23), if the GUI has been started with-server=1, bitcoin-qt hangs on shutdown during calling any of the waitfor* commands in the GUI RPC console.
This PR suggests minimal changes to fix this bug.
Fix #17495