Close sessions when doing background jobs