mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-05-09 05:35:30 +02:00
[PR #348] [MERGED] Fix duplicate HMS error notifications from race condition #1005
Labels
No labels
A1
automated
automated
bug
bug
Closed due to inactivity
contrib
dependencies
dependencies
duplicate
enhancement
feedback
hold
invalid
Notes
P1S
pull-request
security
security
ThumbsUp
user-report
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/bambuddy#1005
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 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.0b← Head:fix/duplicate-error-notifications📝 Commits (2)
1079474Fix duplicate HMS error notifications from race conditionc5246e6Merge 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
After Fix

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.