Clean up notification handles returned from Observable queries. Added condition to test case. Fixes #17394.
(cherry picked from commit bda7e1d7a804b4fd640ef91ae3cbdf94afb49336)