Ensure correct end/close handler correct async behavior

@purplefox would you mind to review this ?
nope, I'll correct it with a corresponding test