Guard against session close from session thread

Fixes CPP-161