java.lang.AssertionError: Session disappeared. #2375

@damithc made the changes mentioned in the issue. Will need to test it out in actual situations to see if it helps though.

Fixes #2375