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

WIP - Ticker Rewrite #2996

Closed
wants to merge 72 commits into from
Closed

Conversation

TheBusyBiscuit
Copy link
Member

Description

This Pull Request was originally created by @LinoxGH, see #2290.

We have decided that it is not ready to merged into master yet as there is still a lot that needs to be tweaked.
That's why I am reopening it under a new branch inside the main repository.

Proposed changes

This makes some changes to the way TickerTask schedules its tasks.

Checklist

  • I have fully tested the proposed changes and promise that they will not break everything into chaos.
  • I have also tested the proposed changes in combination with various popular addons and can confirm my changes do not break them.
  • I followed the existing code standards and didn't mess up the formatting.
  • I did my best to add documentation to any public classes or methods I added.
  • I have added Nonnull and Nullable annotations to my methods to indicate their behaviour for null values
  • I added sufficient Unit Tests to cover my code.

md5sha256 and others added 6 commits July 4, 2021 11:51
This commit changes TickerTask#halt to block and process all remaining tasks.
…n/tasks/TickerTask.java

Co-authored-by: Daniel Walsh <walshydev@gmail.com>
Co-authored-by: Daniel Walsh <walshydev@gmail.com>
@md5sha256
Copy link
Contributor

md5sha256 commented Jul 5, 2021

I think this can now be un-marked as a draft.

@TheBusyBiscuit
Copy link
Member Author

I think this can now be un-marked as a draft.

Compilation failure
Error:  /home/runner/work/Slimefun4/Slimefun4/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/TickerTask.java:[438,39] unreported exception java.lang.InterruptedException; must be caught or declared to be thrown

@md5sha256
Copy link
Contributor

What... this compiled fine for me yesterday

@md5sha256
Copy link
Contributor

Ok now that this compiles... can it be un-marked as a draft?

The `processSyncTasks` method had a bug in it which caused an infinite loop. This was running on the main thread (since sync) and thus never terminated.

On shutdown we call `tick()`, this will submit async tasks and process the final sync tasks. In `processSyncTasks` we have a while loop. `while (!plugin.isEnabled() || deadline > System.nanoTime()) {` the plugin is shutting down therefore `isEnabled` will return false meaning this while loop will always trigger. Next we polled the tasks (`syncTasks.poll(MAX_POLL_TIME, TimeUnit.NANOSECONDS);`). When there are none left this will return null. We have a null check and inside that block we haev `if (plugin.isEnabled()) { break; }`. We want to break out of this loop however as mentioned already `isEnabled` will return false and thus causing this infinite loop bug.
@sonarcloud
Copy link

sonarcloud bot commented Jul 7, 2021

Kudos, SonarCloud Quality Gate passed!

Bug C 1 Bug
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

31.0% 31.0% Coverage
0.0% 0.0% Duplication

@TheBusyBiscuit
Copy link
Member Author

@md5sha256
Copy link
Contributor

md5sha256 commented Jul 7, 2021

About thread interruption: I suppose we actually do need to re-interrupt the thread for TickerTask#halt. I misread something regarding re-throwing the exception or re-interrupting, sonarcloud is correct.

@TheBusyBot TheBusyBot added the ⚡ Merge Conflicts This Pull Request has merged conflicts which need to be resolved! label Sep 3, 2021
@md5sha256
Copy link
Contributor

Is unit testing the only thing missing on this PR or are there other issues to be resolved?

@TheBusyBiscuit
Copy link
Member Author

Is unit testing the only thing missing on this PR or are there other issues to be resolved?

I wish I knew

@J3fftw1 J3fftw1 added the Stale Marks a PR as stale. label Jul 29, 2023
@J3fftw1
Copy link
Contributor

J3fftw1 commented Jul 29, 2023

closing this as stale.
Keeping the branch alive however

@J3fftw1 J3fftw1 closed this Jul 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚡ Merge Conflicts This Pull Request has merged conflicts which need to be resolved! 💡 Performance Optimization This pull request improves performance. Stale Marks a PR as stale.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants