Use a field in the session to avoid locking during close rather than setting a flag -- the latter can race.

refs #793