log err before close session

otherwise, LiveServers will panic
panic: Session already closed
Merge branch 'optimization'