-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
WiFiClient - rename flush() to clear() #9453
Conversation
👋 Hello JAndrassy, we appreciate your contribution to this project! Click to see more instructions ...
Review and merge process you can expect ...
|
662e704
to
169469f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable to me. IMO it just needs a better wording on the documentation. @me-no-dev Do you think we can add this to the breaking changes of 3.0.0 ?
169469f
to
06e2528
Compare
@lucasssvaz looks fine to me too. |
There should have been a compile-time warning whenever those now empty So for any similar changes in future PRs, please make compile time warnings whenever those are being called as it is obviously a legacy mistake when you make a call to a function which is now empty and did do stuff before. For example in my project I have searched for countless hours to see why some of my boards suddenly refused to respond to new calls via the webserver and no idea what caused this as it was nearly impossible to reproduce. |
@TD-er |
In my specific use case I have a wrapper for handling chunked transfers when sending replies to HTTP requests. Without my change, the device would appear to be inaccessible for quite a while to just about any HTTP request when it had to serve multiple requests in a burst. The obvious symptoms were:
But my main issue with this is that it is a very significant change, which should have had some compile-time warnings about the API changes. |
in this case it was not possible to add a warning as the flush() function is a valid function (pure virtual in the Client class) and it is not possible to know when it is used wrong |
@JAndrassy
This is exactly why it is a real pain in the *ss to have this PR being merged. You simply don't know when it is being used wrong, not at compile time, not at runtime. You only keep seeing those symptoms. In the platform packages provided by Jason for me to be able to implement support for ESP-IDF5.x this PR was reverted as it is nearly impossible to find all occurences where this is used incorrectly. I do understand that maybe in the past there may have been a poor choice in function naming. But the way this is now 'fixed' is NOT how it should have done as it is simply breaking stuff and you can't tell where it is all broken unless spending countless hours fixing stuff and with any new lib that may be relying on the older implementation you can do it all over again. All those hours needlessly spent on these kind of issues cannot be spent to make sure I can get rid of those older SDK requirements or even implement nice new features. |
IMHO the best way forward would be to generally revert this PR and if there really is a need to make similar changes, there should be found a way to make it work so devs can see at compile-time what needs to be changed. |
why is it hard to find occurrences of "flush()" in the source code? |
You just can't replace As I also need to have my code to work with SDK versions not using this PR. So this is only enforcing the point I tried to make before as why this PR is causing a mess for developers. |
While you're at it, can you also take a look at these:
That's exactly in the area where multiple reports have been filed lately, so I guess it might be related. |
in Parsing.cpp the client.flush() is at the end of the processing of the HTTP request. the response is already sent. If the connection is not kept alive for the next request, then it is closed so why clearing it. If the connection is kept alive for the following HTTP request, then clear() could delete beginning of the following request. But characters remaining in the buffer would make the following request invalid too. So for a reused connection the processing of the request must ensure to read until the exact end of the request. In ArduinoOTA the UDP object is used to receive and send messages. The function |
One of the git blame of these 2 was about a commit of 6+ years ago where the last commit text mentioned something about it being added intentionally. (some commit inbetween about code formatting) Regardless if it might be some code smell of a problem elsewhere, it does seem like those 2 had to be changed too when this PR was merged to keep at least the functionality the same. |
Still the best solution would to revert this PR completely. The regressions caused by this PR are hughe. Even two follow up PRs are already needed to fix the core itself! How many will be needed at end just for the core itself? |
How about instead of reverting it, we have |
I think that's a nice compromise. |
This is a compromise for issues caused by #9453
PR with clear and deprecation created: #10242 |
@me-no-dev Good solution, no silent breaking change anymore. Now there is an info that a mandatory change has be done and still all code is working as expected. |
This is a compromise for issues caused by #9453
this is a repeat of #8871 after networking refactoring.
With a major version release the
flush()
dilemma could be resolved for WiFiClient & co. as last on this platform.I renamed the flush which cleared the rx buffer to
clear()
. but flush is pure virtual in Client so I had to add emptyflush()
The position of the function in file is to group Print (write) related and Stream (read) related functions.
If Arduino adds to Stream class a method to clear the input buffer, it will be most probably named clear() because Stream is taken from Processing and there it has clear().
I analyzed the API of 18 Arduino networking libraries. ESP32 is the only one with wrong implementation of flush().
There is a very bad consequence of using rx clearing flush() instead of proper flush(). It means RX data loss.