Since the only code calling onclose or onend is from the event listeners... shouldn't it be impossible for them to be called multiple times when the listeners are removed when one of them is executed?  If not, then that sounds like a bug in removeListener.