-
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
spiffs fwrite "bad file number" after mqtt disconnect (IDFGH-693) #3149
Comments
Could you please try enabling CONFIG_USE_ONLY_LWIP_SELECT https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/kconfig.html#config-use-only-lwip-select and see if the issue still occurs? That is to narrow down the possible cause. |
tried enabling CONFIG_USE_ONLY_LWIP_SELECT. same result. i closed and reopened by mistake. sorry about that. |
Deleted my old Github account and forgot that it's linked to this issue. I'm here. |
Thanks for the code @lebtron, we were able to reproduce the issue. Will update this thread when the fix is available. |
Thank you :) |
Environment
Problem Description
When mqtt disconnects (esp-tls fail) something goes wrong with spiffs during a file write running on a different task. errno says "Bad file number" after failed
fwrite
(which returns 0)mqtts pem file is embedded in flash using
COMPONENT_EMBED_TXTFILES := key.pem
and access should not affect spiffs file operations. If I reopen the spiffs file after failure I can write to it again.The problem does not happen after mqtt disconnects, but when the file is being written while it disconnects if that makes any sense.
Steps to repropduce
I've attached a project where I stripped down the code to minimum.
1- change
TEST_WIFI_SSID
&TEST_WIFI_PASS
inmain.cpp
to match your setting2-
make -j8 erase_flash flash
you don't need to change the hard coded mqtt server. I've setup a server which has firewall access on port 8443 but nothing is listening which is when the bug shows it self. I'll make sure the server is running until this issue is resolved.
WARNING: the code has an infinite flash write loop. DO NOT leave it running or it will wear out the flash on your device.
Things I tried
Blocking the port with firewall or changing the server to an invalid one produce different mqtt disconnect codes which doesn't seem to affect fwrite operations. However I do get fwrite to fail with errno "No such file or directory" but that happens very rarely and I'm not sure it's relevant.
Setting a time delay for fwrite operations works (most of the time). But that's only because the race condition doesn't happen as often.
If mqtt successfully connects to server and I manually disconnect (server or client). works like expected.
I let an infinite loop connects/disconnects mqtt during a parallel fwrite. works like expected.
The only situation I could find where the problem is occurring is when the port connection is rejected.
Code to reproduce this issue
esp32_bug.zip
Debug Logs
The text was updated successfully, but these errors were encountered: