Which version of Spark are you using?
In Spark 3.0.X, by default, if you have unread messages, you will be warned if you want to close the window.