Backport 'Fix the "removeSession" callbacks (see #5353)'