I have written an application in Tauri, Rust + JS React. When the machine connected to the app stops working, the app sends to database equivalent of the injection but in other state like machine failure to indicate how many injections could have happened during the machine failure and look:
I, [2024-03-28T03:29:07.845214 #723418] INFO -- : [373a6e4c-86cf-47d5-8e6a-ac31ce78d1bc] Parameters: {"cycles"=>[{"injector"=>"ST 70", "state"=>3, "length"=>55, "current_time"=>"3:29:7", "current_date"=>"2024-3-28"}], "cycle"=>{"cycles"=>[{"injector"=>"ST 70", "state"=>3, "length"=>55, "current_time"=>"3:29:7", "current_date"=>"2024-3-28"}]}}
I, [2024-03-28T03:29:07.854491 #723418] INFO -- : [373a6e4c-86cf-47d5-8e6a-ac31ce78d1bc] Completed 200 OK in 9ms (Views: 0.3ms | ActiveRecord: 0.0ms | Allocations: 2381)
This is last log from Rails that was send from my app to Rails server. This request sending is handled by Interval in JS that is fired each 55 seconds as you can see, the length is set to 55, and the request is made with axios library. Everything would be fine if not this – the next request from app came 43 minutes later, as if the app has fallen asleep:
I, [2024-03-28T04:13:40.365444 #723418] INFO -- : [6dae3bff-6f3f-44c4-9961-0b8b2b41f7c2] Parameters: {"cycles"=>[{"injector"=>"ST 70", "state"=>3, "length"=>55, "current_time"=>"3:30:2", "current_date"=>"2024-3-28"}], "cycle"=>{"cycles"=>[{"injector"=>"ST 70", "state"=>3, "length"=>55, "current_time"=>"3:30:2", "current_date"=>"2024-3-28"}]}}
I, [2024-03-28T04:13:40.360601 #723418] INFO -- : [6e537b40-79c4-4cec-82f1-5b348731f892] Started POST "/cycles" for *** at 2024-03-28 04:13:40 +0100
I, [2024-03-28T04:13:40.369729 #723418] INFO -- : [6e537b40-79c4-4cec-82f1-5b348731f892] Processing by CyclesController#create as HTML
I, [2024-03-28T04:13:40.369892 #723418] INFO -- : [6e537b40-79c4-4cec-82f1-5b348731f892] Parameters: {"cycles"=>[{"injector"=>"ST 70", "state"=>3, "length"=>55, "current_time"=>"3:31:52", "current_date"=>"2024-3-28"}], "cycle"=>{"cycles"=>[{"injector"=>"ST 70", "state"=>3, "length"=>55, "current_time"=>"3:31:52", "current_date"=>"2024-3-28"}]}}
I, [2024-03-28T04:13:40.365232 #723418] INFO -- : [89cb0939-2fd8-48f7-b8e1-c8a7f3667771] Started POST "/cycles" for *** at 2024-03-28 04:13:40 +0100
I, [2024-03-28T04:13:40.371292 #723418] INFO -- : [89cb0939-2fd8-48f7-b8e1-c8a7f3667771] Processing by CyclesController#create as HTML
I, [2024-03-28T04:13:40.374927 #723418] INFO -- : [89cb0939-2fd8-48f7-b8e1-c8a7f3667771] Parameters: {"cycles"=>[{"injector"=>"ST 70", "state"=>3, "length"=>55, "current_time"=>"3:32:47", "current_date"=>"2024-3-28"}], "cycle"=>{"cycles"=>[{"injector"=>"ST 70", "state"=>3, "length"=>55, "current_time"=>"3:32:47", "current_date"=>"2024-3-28"}]}}
The app sent all data that was generated during this "hung up" time at once – even though the request came 4:13, the request included data 43 minutes old, as you can see (current_time). And it was like the server was bombed with the data that appeared during this 43 minutes, like JS has realised that he has to send all data to the server. All axios request have been maintained in "cache?" somehow and when the app had woken up, it sent it all at once. The problem is JavaScript is single threaded, I’m aware of this, and in this case there is a lot stuff going on on main thread, but to be honest – I’ve seen app that handle much more and everything works completely fine. What happened guys? Need help. Is there any known issue JS getting frozen for a period of time?
2
Answers
There are lots of variables that change throughout the program and it will be very hard to reproduce this in just a few steps. Basically, there are a machine that sends data whether it's working or not. If it's working - it sends data about injection, Rust with Tauri listens to it and notifes JS with event, JS listens to this event and creates request to API (Rails). Therefore, when the machine stops working, let's assume last machine's cycle lasted 55 seconds, JS create requests that are equivalent to the machine injections cycle but with different state, for example (failure, or scheduled halt) for users to represent how many injections could have happened and as you can assume JS interval handles it. It creates data each interval function call and sends it to the api. It all happens in main thread, there is no any web worker included. I've created entire logic in JS 'cause during this time I felt much better in JS than in Rust. Rust only creates needed window for me and set a server up that listens for connection from machine. Getting back to the topic, whenever machine starts working again, the interval is being cleared and new one is being set up, taking into account new values from machine. Every new request to database creates new Date object in JS. By this date, the difference between injections is calculated and the data is generated. I've noticed that sometimes Date object returns fake information, for example today's. Today is 29'th March, something around 1AM new Date() returned 16'th March and don't know from where it came, I've checked Windows logs, there is no trace about any time change. A little chaos I've created in here but hopes it suffices.
Please provide a minimal reproducible code, so we can take a look. I’ll update this answer once you do.
Couple notes: