For anyone searching for this and maybe even for you:

Best solution is to use EVENT_DISCONNECT on the server.
The manual has an example how to use it properly.


Problem with on_close is that is it never called when the client crashes, and thus the entity remains on the server.