Check that session ID is valid before adding it to the list of session IDs to delete. Fixes #2622