Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix players timing out after a command executes for a while #460

Merged
merged 4 commits into from
Jan 10, 2025

Conversation

neeleshpoli
Copy link
Contributor

@neeleshpoli neeleshpoli commented Jan 6, 2025

Description

Whenever the fill command is run with a large selection, the client times out. This is because the packet processing is halted because it is processing the command. The best way to solve this would be to process the command in a new task so that packet processing in not halted for commands that take longer to run. This should stop the client from timing out when they run a command that has longer run time and if they do time out while a command is running for whatever reason, the client will properly be removed from the server.

Testing

Forcibly cause a timeout (by an extremely large selection with the fill command), and make sure that the player can rejoin the server.

Please follow our Coding Guidelines

@kralverde
Copy link
Contributor

kralverde commented Jan 6, 2025

Canceling tasks is done in the remove_player method. I do not like this fix and if this works it is evidence of a deadlock occurring in the tokio runtime when a timeout happens. look into that code instead

@neeleshpoli
Copy link
Contributor Author

Canceling tasks is done in the remove_player method. I do not like this fix and if this works it is evidence of a deadlock occurring in the tokio runtime when a timeout happens. look into that code instead

Yeah you're right, its more of a band aid fix. I'll see if I can find the deadlock 👍

@neeleshpoli neeleshpoli marked this pull request as draft January 6, 2025 16:46
@neeleshpoli
Copy link
Contributor Author

Ok after some debugging, there is no deadlock, it's just hanging at the process packets stage for some reason 🤷‍♂️

@neeleshpoli
Copy link
Contributor Author

After some more debugging, I found the actual issue. So whenever the fill command is ran with a large selection, the client times out. This is because the packet processing is halted because it is processing the command. The best way to solve this would be to process the command in a new task so that packet processing in not halted for commands that take longer to run. This should stop the client from timing out when they run a command that has longer runtime and if they do time out while a command is running for whatever reason, the client will properly be removed from the server.

@kralverde
Copy link
Contributor

If it's cpu intensive, use a rayon task (but use an async waiting method if you need to wait on it) otherwise use a tokio task

@neeleshpoli
Copy link
Contributor Author

neeleshpoli commented Jan 7, 2025

If it's cpu intensive, use a rayon task (but use an async waiting method if you need to wait on it) otherwise use a tokio task

Whenever a command is ran, a new tokio task will be spawned now since they are all async anyway. If it needs to, the command itself would have to spawn a rayon task.

@neeleshpoli neeleshpoli changed the title Fix players not being removed from world on timeout Fix players timing out after a command executes for a while Jan 7, 2025
@neeleshpoli neeleshpoli marked this pull request as ready for review January 7, 2025 02:03
@Snowiiii
Copy link
Member

Snowiiii commented Jan 7, 2025

What about Commands executed in Console or RCON ?

@neeleshpoli
Copy link
Contributor Author

What about Commands executed in Console or RCON ?

Oh yeah, I didn't think about that. I can fix those too.

@neeleshpoli neeleshpoli marked this pull request as draft January 7, 2025 13:16
@neeleshpoli neeleshpoli marked this pull request as ready for review January 8, 2025 14:42
@Snowiiii
Copy link
Member

Snowiiii commented Jan 9, 2025

I'm not sure, but can't/should we just spawn a new tokio thread in the dispatcher::handle_command function ?

@neeleshpoli
Copy link
Contributor Author

I'm not sure, but can't/should we just spawn a new tokio thread in the dispatcher::handle_command function ?

Yes we could, but however there are many lifetime issues to resolve before that's possible. Thats why I spawned a task around the handle_command function instead.

@neeleshpoli
Copy link
Contributor Author

Seems like something was pushed to master which also broke CI. I force pushed my branch back.

@Snowiiii
Copy link
Member

I mean for now its fine. Thank you @neeleshpoli 👍

@Snowiiii Snowiiii merged commit 7885da7 into Pumpkin-MC:master Jan 10, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants