- removing entities that shouldn't be removed such as "player" entities
- removing entities thats invalid or doesn't exist
Like I said, I didn't read the code and I was just pointing out one of the reason that might be causing the server to hang/crash. Try commenting those lines that removing entities, just for sake of testing and see if the crashes stop.