-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Wrong HTTPS example fixed. Will save others my #5734 hours of debugging #5739
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
Conversation
Serial.println(payload); | ||
/* in order to ensure the client object lives the entire time of the HTTPClient | ||
the HTTPClient is in its own nested code block */ | ||
{ |
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.
HTTPClient doesn't need to be in its own code block, it just needs to be instantiated after client. Destructors are called in reverse order, which ensures https gets destroyed first and client second.
I suggest removing the code block, and updating the comment to explain this.
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.
I don't agree. It's way too dangerous to rely on order of code lines. Took me two days to debug that. It should be totally explicit, IMHO.
HTTPClient https; | ||
/* in order to ensure the client object lives the entire time of the HTTPClient | ||
the HTTPClient is in its own nested code block */ | ||
{ |
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.
Same as above.
@joysfera The nested block is not the preferred way but the information or warning is relevant. |
I understand you don't want to accept the nested block solution. However, I don't agree with a "solution" based on the order of variable declarations. Adding a comment doesn't really "fix" that. |
Closing as abandoned with changes requested. |
The provided HTTPS examples are misleading and plain wrong because don't ensure the client object lives longer than the https object, which is required per comment hidden in the source code. Otherwise nasty crashes will occur (#5734 ). I have fixed it using a nested code block and a clear comment.