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

Unhandled exceptions in fort #436

Open
SapiensAnatis opened this issue Oct 7, 2023 · 3 comments
Open

Unhandled exceptions in fort #436

SapiensAnatis opened this issue Oct 7, 2023 · 3 comments
Labels
bug Something isn't working technical debt Refactoring that doesn't add a feature

Comments

@SapiensAnatis
Copy link
Owner

The fort services throw a lot of unhandled exceptions

image

Some examples:

  • Building not finished upgrading
  • Not enough smithywyrms

Need to investigate. Are we doing something wrong and is the client calling these endpoints because it thinks the request is valid when it isn't?

If the client is allowing players to do these actions and expecting the server to reject them, we should rework the code to reject them before we start processing the request and not throw an unhandled exception.

@SapiensAnatis SapiensAnatis added bug Something isn't working technical debt Refactoring that doesn't add a feature labels Oct 7, 2023
@SapiensAnatis
Copy link
Owner Author

Have not been able to trigger smithywyrms manually, could be a race condition?

SapiensAnatis added a commit that referenced this issue Oct 31, 2024
Adds some logging to dump the state of the fort when this exception
occurs. Contributes to #436
SapiensAnatis added a commit that referenced this issue Oct 31, 2024
Investigating as part of #436.

Adds some debug logging to indicate the state of the fort at the time
these exceptions get thrown.
@SapiensAnatis
Copy link
Owner Author

'Building not finished upgrading' appears to be a repeated request, but with a different request token?

image

On the second request, the BuildEndDate is the unix epoch so we fail the first part of this check:

if (build.BuildStatus is not FortBuildStatus.LevelUp || time < build.BuildEndDate)

@SapiensAnatis
Copy link
Owner Author

SapiensAnatis commented Nov 2, 2024

'Not enough builders' looks like it could be a logic error in how we calculate the available builders. We assume that any building that is under construction consumes a builder, even if it is finished:

public async Task<int> GetActiveCarpenters() =>

But after the debug logging was added, I noticed it affects new players building low-level facilities that finish quickly. After trying this myself, I noticed that if you build a facility that takes e.g. 5 seconds, your builder count goes to 3/4, but when it finishes, the client self-increments the builders back to 4/4.

I think we need to change GetActiveCarpenters to exclude buildings that are finished.

SapiensAnatis added a commit that referenced this issue Nov 2, 2024
Contributes to #436. Changes the used carpenter count calculation to be based on the number of buildings currently under construction which aren't finished, rather than any building that has a non-zero BuildEndDate.

This is because if you start an upgrade that takes e.g. 10 seconds, we report you have 3/4 builders. That's fine. But when the client sees that build complete using its internal timer, it then believes 4/4 builders are available, but we currently would say it's still 3/4 until you actually call levelup_end by tapping the building. This desync was causing the FortBuildCarpenterBusy exception.
SapiensAnatis added a commit that referenced this issue Nov 2, 2024
Contributes to #436. Changes the used carpenter count calculation to be
based on the number of buildings currently under construction which
aren't finished, rather than any building that has a non-zero
BuildEndDate.

This is because if you start an upgrade that takes e.g. 10 seconds, we
report you have 3/4 builders. That's fine. But 10 seconds later, when
the client sees that build complete using its internal timer, it then
believes 4/4 builders are available, but we currently would say it's
still 3/4 until you actually call levelup_end by tapping the building. I
believe this desync is what causes the FortBuildCarpenterBusy exception.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working technical debt Refactoring that doesn't add a feature
Projects
None yet
Development

No branches or pull requests

1 participant