This should fix a regression introduced with #8845 with reopening a running shell. Adds more checks and more verbose logging messages on failures.