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

Add await writer.drain() after writer.write() for proper flow control #126

Merged
merged 1 commit into from
Oct 22, 2024

Conversation

allrob23
Copy link
Contributor

Summary

This PR adds await writer.drain() after writer.write() calls to ensure proper flow control and prevent potential data loss or write buffer overflows when interacting with asyncio streams.

Rationale

According to the Python asyncio documentation, writer.write() only queues data, and it’s necessary to call await writer.drain() to ensure the data is properly written when the internal buffer is full. The drain() method blocks when the buffer is full, preventing overflows and ensuring all data is transmitted before continuing execution. Without this, there is a risk of data not being fully sent or written.

This change ensures the write buffer is correctly managed, especially in cases of high-volume or rapid write operations, maintaining stream reliability and preventing potential issues in production environments.

@alengwenus alengwenus merged commit ee7c34f into alengwenus:dev Oct 22, 2024
10 checks passed
@alengwenus
Copy link
Owner

Thanks @allrob23 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants