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

TempBuffer memory allocation failure should not use Serial.printf() #822

Open
frankonski opened this issue Mar 28, 2024 · 2 comments
Open

Comments

@frankonski
Copy link
Contributor

The new TempBuffer class will use Serial.printf() if memory allocation fails, then get into an infinite loop to stall the program.

The method Serial.printf() actually requires a mix of stack and heap memory, so there is a chance that the Serial.printf() text logged by HomeSpan may never get logged.

Back-to-back Serial.print() should be used instead.

This may be the reason why I posted the comment at #791 (comment) about HomeSpan's CLI becoming fully unresponsive even though nothing got logged to the serial console.

@HomeSpan
Copy link
Owner

Have you been able to confirm that this is indeed the problem. If an alloc() fails, nothing bad happens. The memory is simply not acquired. There should still be plenty of heap for printf to produce the output.

Note that serial monitors are not fully stable. If I leave mine up for a while and my MAC goes to sleep I often need to close and re-open the serial monitor for it to re-establish a USB connection.

@frankonski
Copy link
Contributor Author

Have you been able to confirm that this is indeed the problem.

Not yet.

If an alloc() fails, nothing bad happens.

well, stalling the whole program in a while(1) loop with no logging (assuming this is the issue) is somewhat bad imo. The calling method failing to get a TempBuffer should decide how to handle this scenario, ideally.

There should still be plenty of heap for printf to produce the output.

Ideally, I agree, yes.

need to close and re-open the serial monitor for it to re-establish a USB connection.

That, I tried. No luck, no wake up, power still in D0. My only suspicion right now was these while(1)

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

No branches or pull requests

2 participants