Agent in out of memory looping error - worked around

WORKED AROUND ISSUE BY CREATING NEW ACCOUNT (see below post).

Somehow got my imp and agent to go crazy and I think I’ve overflowed the agent storage (server.save()). I’ve removed the code and just trying to do server.save() with an empty table but it’s not working.
Any suggestions how to reset it?
imp005: 5000a408eab9a486
Thanks.

What’s the code returned by the server.save() call? What are you seeing in terms of agent logs when you restart the device and then your agent code calls server.save({})?

It won’t run the server.save() call to see what it returns.

Agent code:

local value = 0;
local fifoTable = {};
fifoTable = {“zero”: value};
server.log(server.save(fifoTable));

Device code:

server.log(“device started empty”);

Log:

|2018-03-23 06:29:14 +10:30|[Status]|Device connected|
|2018-03-23 06:29:14 +10:30|[Status]|Agent started.|
|2018-03-23 06:29:14 +10:30|[Agent]|ERROR: Out of memory (1024kB used)|
|2018-03-23 06:29:14 +10:30|[Device]|device started empty|
|2018-03-23 06:29:18 +10:30|[Status]|Agent restarted: after delay.|
|2018-03-23 06:29:18 +10:30|[Agent]|ERROR: Out of memory (1024kB used)|
|2018-03-23 06:29:28 +10:30|[Status]|Agent restarted: after delay.|
|2018-03-23 06:29:28 +10:30|[Agent]|ERROR: Out of memory (1024kB used)|

The log just continues with the error/agent restarted message pair about every 10secs.

Worked around the issue. Have created a new account and migrated to the new account. If you can find the old agent, you can reset it from looping. Sorry, had to keep working and there was no way for me to reset the agent (I also tried reblinking the device).

We’ve seen a similar problem once before: the server.save() data is stored as JSON, and it’s serialised twice. Once inside the agent runtime to check the size, and once inside the Erlang host to actually save the data. The two don’t agree exactly on serialisation, so occasionally a large blob (or string, we’ve not nailed it down) will get transformed into an array of integers.

When that gets read back in, it blows the memory allowance.

The only way to clear this situation is for us to clear the saved data internally, which requires raising a support ticket. Or, as you found, you can change the account associated with the device. Changing it back just puts you back in the same situation, however.

We started work to change the way we store saved data, mainly to remove the restrictions caused by using JSON, but it would also solve this problem. Unfortunately, that work has been temporarily shelved and has dropped down the priority list.

I don’t exactly know either what caused it. Not to keen to try and replicate :slight_smile: I do know things happened very quickly with data coming from the device to the agent. That possibly contributed to it or caused it. Your explanation does make sense though.
For the imp teams consideration - maybe a button or something in the ide that blows away the agent vm and creates a new one. Not sure how that would work or if its even feasible. I’m not a perfect programmer so do at times make mistakes that have the potential to cause a problem too.
Thanks anyway :slight_smile:

How do I get the agent reset?
I’ve put the imp005 (referred to in initial post) back to my account after almost 6 months and the first thing it does is report out of memory looping with:

2018-09-17 12:35:48 +09:30 [Agent] ERROR: Out of memory (1024kB used)
2018-09-17 12:35:58 +09:30 [Status] Agent restarted: after delay.

I thought if I move the imp to a different account for a while (more than 5 months) the agent would be cleared and reconstructed when I re-connect.

The code it had in the agent side is:

server.log("**** Agent code starts");
local fifoTable = {};
local value = 0;
fifoTable = {"value": 0};
server.save(fifoTable);

Thanks for your help :slight_smile:

Is that the complete agent code? The listed code alone won’t cause the OOM errors (at least not for me).

Just comment out all of your agent code and restart the device in impCentral. That will restart the agent with no code, allowing you to debug as you add it back.

HiTony,
No luck.
Blank Agent and just a server.log(“device started”) in device side returns:

2018-09-17 22:14:26 +09:30 [Status] Downloading new code; 0.26% program storage used
2018-09-17 22:14:27 +09:30 [Device] device started
2018-09-17 22:14:26 +09:30 [Status] Agent started.
2018-09-17 22:14:26 +09:30 [Agent] ERROR: Out of memory (1024kB used)
2018-09-17 22:14:34 +09:30 [Status] Agent restarted: after delay.

If you give me the device ID, I can clear the saved data for the agent.

Hi Roger,
Details sent in a PM.
Thanks. :smile:

Done. (filler to make this up to the minimum required 20 characters)

Hi Roger,

May you help me restarting my agent?
The ID device is: 30000c2a690c95d6

If you need another information, just let me know.

Thanks,
JO.

You can restart your agent by just changing any text in the source and pressing “build and restart” (or by using “impt device restart”, see https://github.com/electricimp/imp-central-impt/blob/master/DevelopmentGuide.md#creating-and-running-builds )

1 Like

Your agent is restarting because it’s running out of memory. Unlike the OP, this isn’t caused by server.save data, so there’s likely a bug in your code. As @hugo says, you can just push new code to your agent by pressing “build and restart”.

1 Like