slgobinath / SafeEyes

Protect your eyes from eye strain using this simple and beautiful, yet extensible break reminder
http://slgobinath.github.io/SafeEyes/
GNU General Public License v3.0
1.46k stars 164 forks source link

When deleting a break, there is a chance it hangs forever on closing the settings screen, and on subsequent startup. #567

Open deltragon opened 8 months ago

deltragon commented 8 months ago

Describe the bug Deleting the break that happened to be the next scheduled one will remove the break from the existing queue, but keep it as last_break in the BreakQueue. This leads to an infinite loop in this code: https://github.com/slgobinath/SafeEyes/blob/00c33908a3e861f19d0fcb2df54ecaf48b93e66a/safeeyes/model.py#L110-L113

To Reproduce Steps to reproduce the behavior:

  1. Start SafeEyes.
  2. Ensure that there are exactly two breaks, and delete all breaks except those (eg. "Tightly close your eyes" and "Have some water"). This is needed to increase the likelyhood of the bug happening, but can occur with any number of breaks.
  3. Click on 'Take a break now' -> 'Any Break'.
  4. After the break, open the Settings.
  5. Go to the break list.
  6. Delete either break (eg. "Have some water").
  7. Click "Delete" in the confirmation dialog.
  8. Try to close the settings dialog - this will hang in about 50% of the time.

Since it is a coinflip each time, it is needed to repeat step 2-7 a few times to reproduce.

Expected behavior Deleting any break should not hang.

Desktop (please complete the following information):

Debug Log Run the Safe Eyes using safeeyes --debug command attach the ~/safeeyes.log` file.

2024-03-06 20:26:18,911 [INFO]:[Thread-7] Start Safe Eyes core
2024-03-06 20:26:18,912 [INFO]:[WorkThread] Waiting for 15 minutes until next break
2024-03-06 20:26:18,912 [INFO]:[MainThread] Update next break information
2024-03-06 20:26:21,881 [INFO]:[MainThread] Show Settings dialog
2024-03-06 20:26:29,394 [INFO]:[MainThread] Saving settings to safeeyes.json
2024-03-06 20:26:29,394 [INFO]:[MainThread] Disable Safe Eyes
2024-03-06 20:26:29,395 [INFO]:[MainThread] Stop Safe Eyes core
2024-03-06 20:26:29,395 [INFO]:[WorkThread] Pre-break waiting is over
2024-03-06 20:26:29,396 [INFO]:[MainThread] Initialize SafeEyesCore with modified settings
2024-03-06 20:26:29,396 [INFO]:[MainThread] Initialize the core

After Initialize the core, it will hang.

deltragon commented 8 months ago

Since I know what the issue is, I am planning to file a PR fixing it. I just wanted to file this to make sure it doesn't get lost.

deltragon commented 8 months ago

Oh, I've found a new reproducer:

  1. Start SafeEyes.
  2. Click on 'Take a break now' -> 'Any Break'.
  3. After the break, open the Settings.
  4. Delete all breaks.
  5. Add completely new breaks with different names to the existing breaks.
  6. Try to close the settings dialog - this will hang 100% of the time.

Step 4 and 5 can also be using the "Reset" button, if there is no overlap between the names of the breaks in Step 1 and 2 and the default breaks.