[#1284] Fix bug which can cause in infinity-loop triggered by a handler removal