The invalid handle is on the list only for a very short period, but the period spans two critical sections so there is an opportunity for another thread to get in and do something. If the "something" involves calling cancelAllHeartbeats, the test will crash due to canceling an invalid handle.
We should fix this, probably by using a valid dummy handle (e.g. to a do-nothing lambda).