check session closing before writing