You cannot guarantee the state of the server in a web app. What you are doing is not going to work on a heavily loaded system.