1
0
Fork 0
mirror of https://github.com/maziggy/bambuddy.git synced 2026-05-09 08:25:54 +02:00

[PR #348] [MERGED] Fix duplicate HMS error notifications from race condition #1012

Closed
opened 2026-05-07 00:15:28 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/maziggy/bambuddy/pull/348
Author: @sbcrumb
Created: 2/12/2026
Status: Merged
Merged: 2/13/2026
Merged by: @maziggy

Base: 0.2.0bHead: fix/duplicate-error-notifications


📝 Commits (2)

  • 1079474 Fix duplicate HMS error notifications from race condition
  • c5246e6 Merge branch '0.2.0b' into fix/duplicate-error-notifications

📊 Changes

1 file changed (+3 additions, -2 deletions)

View changed files

📝 backend/app/main.py (+3 -2)

📄 Description

Description
Fix duplicate HMS error notifications caused by a race condition in the async status callback handler. When multiple status updates arrive concurrently, both callbacks could read _notified_hms_errors as empty before either updates it, resulting in the same error notification being sent 2+ times.

The fix moves the _notified_hms_errors tracking update to before the async notification send, matching the pattern already used by the milestone tracking code which doesn't have this bug.

Related Issue
N/A — discovered during testing of notification behavior.

Type of Change
Bug fix (non-breaking change that fixes an issue)
New feature (non-breaking change that adds functionality)
Breaking change (fix or feature that would cause existing functionality to change)
Documentation update
Code refactoring
Performance improvement
Test addition or update

Changes Made
Moved _notified_hms_errors[printer_id] = current_error_codes from after the notification await to before it, preventing concurrent callbacks from both treating the same errors as new
Removed the now-unnecessary tracking update that was after the try/except block
Screenshots
Before Fix
Screenshot_2026-02-12-10-32-57-80_b0dee7ef33e01af84433b30b99d6e2f9

After Fix
Screenshot_2026-02-12-10-32-41-20_b0dee7ef33e01af84433b30b99d6e2f9

Testing
I have tested this on my local machine
I have tested with my printer model: H2S

Checklist
My code follows the project's coding style
I have commented my code where necessary
I have updated the documentation (if needed)
My changes generate no new warnings
I have tested my changes thoroughly

Additional Notes
The root cause: on_printer_status_change is an async callback that can be invoked concurrently. The milestone tracking (line 371) already updates its tracking dict before the await, so it doesn't have this issue. The HMS error tracking was updating after the await, creating a window where a second callback could send duplicates.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/maziggy/bambuddy/pull/348 **Author:** [@sbcrumb](https://github.com/sbcrumb) **Created:** 2/12/2026 **Status:** ✅ Merged **Merged:** 2/13/2026 **Merged by:** [@maziggy](https://github.com/maziggy) **Base:** `0.2.0b` ← **Head:** `fix/duplicate-error-notifications` --- ### 📝 Commits (2) - [`1079474`](https://github.com/maziggy/bambuddy/commit/107947495debe3465efb0e5fcd80c19b6a1629dd) Fix duplicate HMS error notifications from race condition - [`c5246e6`](https://github.com/maziggy/bambuddy/commit/c5246e60fc555c90198b6e7c7a44034a4f8ef382) Merge branch '0.2.0b' into fix/duplicate-error-notifications ### 📊 Changes **1 file changed** (+3 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `backend/app/main.py` (+3 -2) </details> ### 📄 Description Description Fix duplicate HMS error notifications caused by a race condition in the async status callback handler. When multiple status updates arrive concurrently, both callbacks could read _notified_hms_errors as empty before either updates it, resulting in the same error notification being sent 2+ times. The fix moves the _notified_hms_errors tracking update to before the async notification send, matching the pattern already used by the milestone tracking code which doesn't have this bug. Related Issue N/A — discovered during testing of notification behavior. Type of Change Bug fix (non-breaking change that fixes an issue) New feature (non-breaking change that adds functionality) Breaking change (fix or feature that would cause existing functionality to change) Documentation update Code refactoring Performance improvement Test addition or update Changes Made Moved _notified_hms_errors[printer_id] = current_error_codes from after the notification await to before it, preventing concurrent callbacks from both treating the same errors as new Removed the now-unnecessary tracking update that was after the try/except block Screenshots Before Fix ![Screenshot_2026-02-12-10-32-57-80_b0dee7ef33e01af84433b30b99d6e2f9](https://github.com/user-attachments/assets/64bf5b3c-d1f2-473f-a90e-084382d55cfa) After Fix ![Screenshot_2026-02-12-10-32-41-20_b0dee7ef33e01af84433b30b99d6e2f9](https://github.com/user-attachments/assets/992f841b-e58e-444d-b513-ad007fafdb06) Testing I have tested this on my local machine I have tested with my printer model: H2S Checklist My code follows the project's coding style I have commented my code where necessary I have updated the documentation (if needed) My changes generate no new warnings I have tested my changes thoroughly Additional Notes The root cause: on_printer_status_change is an async callback that can be invoked concurrently. The milestone tracking (line 371) already updates its tracking dict before the await, so it doesn't have this issue. The HMS error tracking was updating after the await, creating a window where a second callback could send duplicates. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-07 00:15:28 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/bambuddy-maziggy-1#1012
No description provided.