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

classicAttackSpeed makes server go 100% CPU #4676

Closed
gesior opened this issue May 10, 2024 · 0 comments · Fixed by #4677
Closed

classicAttackSpeed makes server go 100% CPU #4676

gesior opened this issue May 10, 2024 · 0 comments · Fixed by #4677

Comments

@gesior
Copy link
Contributor

gesior commented May 10, 2024

Steps to reproduce

  1. Turn on classicAttackSpeed in config.lua
  2. Login 2 players few SQM from each other.
  3. Attack one player using melee weapon.
  4. Watch how number of doAttacking (or checkCreatureAttack) executions per second grows over time (OTS Stats or add 'std::cout' in that function)

You can make it go high faster by running around. Each step of attacked/attacking player adds 1 extra event.

Expected behaviour

Server checks players attacks every getAttackSpeed() - once, not multiple times.

Actual behaviour

Server adds new checkCreatureAttack event to Scheduler every second (onThink) and every player step. Each event is recurring, if target cannot be hit by player.
Server generates infinite number of Scheduler events and CPU goes 100% after few minutes/hours.

Environment

Tested on TFS 1.4, but master code looks the same.

Fix

  1. In player.h under:
uint32_t walkTaskEvent = 0;

add:

uint32_t classicAttackEvent = 0;
  1. In player.cpp in function void Player::doAttacking(uint32_t) replace:
g_scheduler.addEvent(task);

with:

g_scheduler.stopEvent(classicAttackEvent);
classicAttackEvent = g_scheduler.addEvent(task);

It will limit number of checkCreatureAttack events to 1 per player.

gesior added a commit to gesior/forgottenserver-gesior that referenced this issue May 10, 2024
@EPuncker EPuncker linked a pull request May 10, 2024 that will close this issue
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 a pull request may close this issue.

1 participant