Update close method. Completely shut down a session only when previous
on-going responses has finished.