Register session close on shutdown at the start of session handling

This is necessary to make sure session data is saved on redirect.
Merge pull request #571 from protich/issue/close_session_on_shutdown

Register session close on shutdown at the start of session handling

Reviewed-By: Jared Hancock <jared@osticket.com>