Fix 10 second delay in WiFiClient read methods when no data is available to read#458
Merged
andreagilardoni merged 2 commits intoarduino:mainfrom Mar 18, 2025
Conversation
…of that data is zero
Comment on lines
+301
to
+303
| if (sized_read_size == 0) { | ||
| state = at_parse_state_t::Res; | ||
| } |
Contributor
There was a problem hiding this comment.
I would remove the state transition at line 297 and keep the state change next to each other. This will improve the readability.
Suggested change
| if (sized_read_size == 0) { | |
| state = at_parse_state_t::Res; | |
| } | |
| if (sized_read_size != 0) { | |
| state = at_parse_state_t::Sized; | |
| } else { | |
| state = at_parse_state_t::Res; | |
| } |
Contributor
Author
There was a problem hiding this comment.
Thanks for the good suggestion - I have added another commit to address.
andreagilardoni
requested changes
Mar 18, 2025
Contributor
andreagilardoni
left a comment
There was a problem hiding this comment.
@mgcookson Thanks for your contribution, it is really appreciated!
andreagilardoni
approved these changes
Mar 18, 2025
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 Summary
Prior to v1.3.0 of core, invoking either
WiFiClient::read()orWiFiClient::read(uint8_t *buf, size_t size)when there was no data available to read would result in those methods returning immediately with expected return codes (-1 for the former and 0 for the latter).As of v1.3.0, both 'read' methods now unexpectedly delay for 10 seconds in the 'no data available' scenario before returning the expected return codes. This change in behavior was introduced via PR #349.
Proposed Fix
This PR contains a proposed fix that allows the state machine used to read (WiFi) modem responses to immediately transition to the next state when the indicated data length in the response is zero, instead of getting stuck in the 'read data' state.
Research Notes
Example affected code excerpts with results
Code invoking WiFiClient::read()
Results when run under core 1.2.2
Results when run under core 1.4.1
Code invoking WiFiClient::read(uint8_t *buf, size_t size)
Results when run under core 1.2.2
Results when run under core 1.4.1
Modem.cpp debug output before and after proposed fix
Enabling modem debug output using
modem.debug(Serial, 3)yields the following results:Results when run under core 1.4.1 prior to this fix
Results when run under core 1.4.1 after this fix