failed with create/get/patch documents #28
Replies: 22 comments 9 replies
-
Thank you for informing this problem. It's seem to be a bug and will fix and inform you soon. |
Beta Was this translation helpful? Give feedback.
-
okay, thanks for your reply. |
Beta Was this translation helpful? Give feedback.
-
The library update is available with many features added and bugs fixed. |
Beta Was this translation helpful? Give feedback.
-
Thanks @mobizt .It's works well after latest update. |
Beta Was this translation helpful? Give feedback.
-
Here is my first exception code: Exception (9):
ctx: bearssl ctx: cont Exception 9: LoadStoreAlignmentCause: Load or store to an unaligned address Decoding stack results |
Beta Was this translation helpful? Give feedback.
-
And here is the seconde exception. Exception (29):
ctx: cont last failed alloc call: 40246804(1993) Exception 29: StoreProhibited: A store referenced a page mapped with an attribute that does not permit stores Decoding stack results |
Beta Was this translation helpful? Give feedback.
-
The first decoded error is you don't have enough memory for SSL handshaking. Both errors occurred when you call getJSON. You free memory is not enough for making a request. |
Beta Was this translation helpful? Give feedback.
-
Okay. I test my code in last two days. If i only use streaming to a RTDB node(call node1), the code seems works well, and same test result to only receive another node(call node2) periodically, but wdt reset will triggerd if use streaming to node1 and receive node2 periodically. I also use the esp8266 api to get free heap size( In my whole code i clear the FirebaseData object everytime i received data(only clear the receive FirebaseData object, the streaming FirebaseData object will not do this), and cleared FirebaseJson object, and deconstructor the FirebaseJsonData object at the end of the function if i used them. Could i effectively reduce used heap size by doing this? Or is it unnecessary? |
Beta Was this translation helpful? Give feedback.
-
The free memory required for SSL client operation especially in handshaking and will not free until the connection was closed. The SSL handshaking may fail when no enough memory. Call the member function clear from Firebase Data object also stop the SSL client and release the resources. Call the member function clear from FirebaseJson will clear the internal dynamic allocation memory but some are not freed until the object goes out side the scope. The FirebaseJsonData class doesn't have the clear function. The memory also reserved by internal SSL client for buffering with function setBSSLBufferSize of the Firebase Data object. The stream Firebase Data object should be defined as global while Firebase Data object and FirebaseJson object can define as local var. You should test everything and manage your own usages which I can't recommend or give the solution based on your situation. |
Beta Was this translation helpful? Give feedback.
-
Okay. I will continue to test. Thanks for your clearly explanation, i will post the main problem here if i found it. |
Beta Was this translation helpful? Give feedback.
-
Hello @mobizt, in this few days i try several experiment with my code and example code.
Then the test result still crashed at sometimes, and before the code crashed, the output will occur that like not connected or read Timeout. In example code i also got crashes at some time, but before the crashes, it seems like have the same situation with my code. |
Beta Was this translation helpful? Give feedback.
-
If you want to get the actual stream event data payload, in this case for testing, don't use multiPathStream which do post processing the data and can be failed in truncated, incomplete JSON, use normal stream functions. You need to provide more SSL tx buffer (BearSSL) and response size for JSON payload (see the setup in examples). The crash can be in the id token exchange and refreshment process which required time and resources to handle the token. If you want stable operation but less secure at this time, use the legacy token (database secret). |
Beta Was this translation helpful? Give feedback.
-
Hello @mobizt , i had try my code before and still get crash after some hours later, so i give up test my code and back to test the But after a few hours later it will crash again, but i found a little problem with here. When i try to add the Following file is the output. I also try to remove I use the exception decoder and get the crash is at this line I also use the debug in Arduino IDE to get the ssl+http client message. I observe that every time it request to Firebase, it will output bearssl encrypt message like following:
I found that before the code crashed, bearssl connect will first output, and then start to access Firebase, the code be crash again. Sorry to trouble you so many times. |
Beta Was this translation helpful? Give feedback.
-
The new version of library is available with the bugs fixed, please update. |
Beta Was this translation helpful? Give feedback.
-
Hello @mobizt , i test the force refresh token as you say, but i got some confused points.
Here is the stream data structure: |
Beta Was this translation helpful? Give feedback.
-
The library updated with the issues fixed. Please update. The crash issue is due to sometime the memory is not sufficient for refresh token handling in ESP8266. In ESP8266 with Email/Password Sign-in Authentication method, the new id token will be generated instead of refreshment because the response payload is 40% smaller than the token refreshment payload. |
Beta Was this translation helpful? Give feedback.
-
Thanks @mobizt , after this update the memory insufficient issue is going out.
So i remove the Ticker library and continue to test my code, after 2 days and hours, it crashed again, and the output is similar: |
Beta Was this translation helpful? Give feedback.
-
It's not related to the library unless the available free heap is not enough. You should debug your own memory usage to prevent stack overflow and running out of heap. |
Beta Was this translation helpful? Give feedback.
-
I confirm this because my device still be running for a week since latest fix the memory leaks. |
Beta Was this translation helpful? Give feedback.
-
The line of code you mentioned is not the issue as it done properly. if (fbdo->httpClient.stream()) //check the WiFiClient object stay existed, not yet disposed prior to use or call it.
{
if (!fbdo->httpClient.stream()->connected()) //check the connection state of WiFiClient object
reconnectStream = true;
} The low memory or memory read/write issue, garbage in memory operation due to low power of onboard LDO may cause randomness and unpredictable issue. The code stop address is not guarantee the root cause is at that address as the operation failed at that line is due to the secondary effect of other issues. |
Beta Was this translation helpful? Give feedback.
-
For esp8266, the stream with callback, readStream will run continuously in the esp schedule as long as Firebase Data object that being use for stream is existed. This consumed stack memory and if you're using the Ticker library (the esp schedule function wrapper) which also use the stack too, the stack (only 4 KB) may over flow. You can avoid stack overflow by using the readStream and stramAvaliable in loop and parse the JSON payload yourself or use millis() for your schedule tasks instead of Ticker. This is the information that may help you to address the problem. |
Beta Was this translation helpful? Give feedback.
-
Hello @mobizt , i test my code and use readstream and streamAvailable in loop, but in last few day i found that the streamAvailable will not trigger in the loop, but the streamCallback is work's fine. |
Beta Was this translation helpful? Give feedback.
-
Hello, mobizt, at first thanks you for providing such a complete Firebase lib, and here i test the Firestoreexample in last few days but i get the error.
Then i found the problem is the example code miss the setting config of host and api_key, as the follows.
But in few days i try to modify the create_documents example that will create a documents 5 min a period, and then it cannot correctly upload a documents to Firestore.
As same as i change the period for 3(or 4) min, and it's works well.
I try to add the httpcode at the failed part, and it got 200 when uploads failed, so i guess the main problem may be that the Firebase connection will lost due to idle too long. So how can avoid this problem?
Here is my test code
/**
*/
//This example shows how to create a document in a document collection. This operation required Email/password, custom or OAUth2.0 authentication.
#if defined(ESP32)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#endif
#include <Firebase_ESP_Client.h>
/* 1. Define the WiFi credentials */
#define WIFI_SSID "WIFI_AP"
#define WIFI_PASSWORD "WIFI_PASSWORD"
#define FIREBASE_HOST "PROJECT_ID.firebaseio.com"
#define API_KEY "API_KEY"
/* 2. Define the project ID */
#define FIREBASE_PROJECT_ID "PROJECT_ID"
/* 3. Define the user Email and password that alreadey registerd or added in your project */
#define USER_EMAIL "USER_EMAIL"
#define USER_PASSWORD "USER_PASSWORD"
//Define Firebase Data object
FirebaseData fbdo;
FirebaseAuth auth;
FirebaseConfig config;
unsigned long dataMillis = 0;
int count = 0;
void setup()
{
#if defined(ESP8266)
//Set the size of WiFi rx/tx buffers in the case where we want to work with large data.
fbdo.setBSSLBufferSize(1024, 1024);
#endif
}
void loop()
{
}
Beta Was this translation helpful? Give feedback.
All reactions