-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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 DISABLE_ASYNCTCP_ACK_TIMEOUTS build flag. #1712
Conversation
Hey there @OttoWinter, mind taking a look at this pull request as its been labeled with an integration ( |
…on not yet accepted pull request: esphome/esphome#1712).
After a long debug session yesterday, @glmnet and me might have ended up with a fix that would make this change no longer needed. I will check that fix on my devices. If things are fixed, I will close this pull request. |
Yes, I'm closing this pull request for now. |
What does this implement/fix?
This change makes it possible to disable AsyncTCP's TCP ACK timeout checks for the API server, which on some systems cause regular faulty API client disconnects. As a workaround, these checks can be disabled by setting the
DISABLE_ASYNCTCP_ACK_TIMEOUTS
build flag.An api component configuration option is provided to make it easy to enable the workaround build flag from the YAML configuration.
Types of changes
Related issue or feature (if applicable): fixes
Pull request in esphome-docs with documentation (if applicable): esphome/esphome-docs#1129
Test Environment
Example entry for
config.yaml
:Initially, I didn't create the api config option for enabling the workaround build flag. Reasons for this were:
However, @jesserockz suggested adding an api option on Discord, so I updated the code to add one.
The coupling was my main concern, but it is not too bad at all. There are currently no other TCP implementations implemented, and even if there were, enabling the build flag would not hurt the build if there were any.
Explain your changes
The AsyncTCP library implements TCP ACK timeout checking in its server code, to check for disconnected clients. When an ACK timeout is spotted, the related client will be forcibly disconnected from the server.
Unfortunately, the implementation of these checks can be a bit buggy at times. This results in API client connections being evicted for no good reason. For users this shows up as devices that regularly get marked as unavailable within Home Assistant.
An attempt was made to fix an identified race condition in pull request #4 for the AsyncTCP fork that is in use by ESPHome. However, as you can read here, the integration of this patched version of AsyncTCP in ESPHome was reverted, because for somebody else, the fix actually resulted in extra disconnects. Although there are other reports that the fix does work, it is of no use when others get into troubles because of it.
Looking into other options, I realized that I could fully disable the ACK timeout checks by setting the timeout to zero. This is a built-in option for the AsyncTCP library. I tested my device with the unpatched version of AsyncTCP, but including the introduced build flag. The result was above expectations. I got a really stable device, which still could detect disconnected clients. For details, check out my little story on this.
Checklist:
tests/
folder).If user exposed functionality or configuration variables are added/changed: