Cleanup before calling user error callback in onclose