fix(tasks): Refactor send_zap to use async websockets and prevent crashes#90
Merged
dni merged 2 commits intolnbits:mainfrom Aug 13, 2025
Merged
fix(tasks): Refactor send_zap to use async websockets and prevent crashes#90dni merged 2 commits intolnbits:mainfrom
dni merged 2 commits intolnbits:mainfrom
Conversation
The send_zap async function contained blocking calls (thread.join()) which halted the main asyncio event loop. This caused the application to become unresponsive or "freeze" until all zap receipt threads completed. Refactored the function to be fully non-blocking by removing the join() calls and the arbitrary sleep(). Zap receipts are now dispatched in background threads on a fire-and-forget basis, allowing the main application to remain responsive.
Refactor to replace the threading and websocket-client logic with the native asyncio websockets library. Create a non-blocking asyncio task for each relay,
talvasconcelos
approved these changes
Aug 13, 2025
Contributor
Author
|
You're welcome. Really, I'm just submitting these PRs as part of fixing my goat feeder. https://lightning-goats.com ;) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem:
The send_zap function was causing application-wide freezes and intermittent crashes. This was due to using a synchronous, thread-based websocket library (websocket-client) from within an asyncio coroutine.
Solution:
This pull request refactors the send_zap function to be fully asynchronous and safe by replacing the threaded implementation with the native asyncio websockets library (which was already a project dependency).
This change eliminates the root cause of the instability, making the send_zap operation non-blocking, efficient, and safe from race conditions.