fix(session): session unavailable in shutdown functions

shutdown functions defined in plugin can't access information in session because this was already closed.

Resubmission of #6722