GenieACS specific packet crash

It’s been a while since I’m testing with GenieACS and I found something curious. It seems my Mikrotik Router is sending a packet that crashes cwmp service.

Looks similar to Genieacs-cwmp process dies and restarts but not quite the same.

This is version 1.2.0 (tried downloading from source on September 1st and also from npm and having same result on both )

This is the exception I’m getting from cwmp:

Sep 02 14:01:17 dbacs genieacs-cwmp[8941]: 2020-09-02T20:01:17.469Z [ERROR] Uncaught exception; pid=9243 exceptionName=“SyntaxError” exceptionMessage=“Unexpected token o in JSON at position 1” exceptionStack=“SyntaxError: Unexpected token o in JSON at position 1\n at JSON.parse ()\n at getOperations (/usr/lib/node_modules/genieacs/bin/genieacs-cwmp:2:58471)\n at process._tickCallback (internal/process/next_tick.js:68:7)”

Sep 02 14:08:25 dbacs genieacs-cwmp[8941]: 2020-09-02T20:08:25.565Z [ERROR] Worker died; pid=9243 exitCode=0

Sep 02 14:08:25 dbacs genieacs-cwmp[8941]: 2020-09-02T20:08:25.810Z [INFO] Worker listening; pid=9292 address=“0.0.0.0” port=7547

It seems the crasher packet from CPE is this one

<soapenv:Envelope xmlns:soap=‘http://schemas.xmlsoap.org/soap/encoding/’ xmlns:xsd=‘http://www.w3.org/2001/XMLSchema’ xmlns:cwmp=‘urn:dslforum-org:cwmp-1-0’ xmlns:soapenv=‘http://schemas.xmlsoap.org/soap/envelope/’ xmlns:xsi=‘http://www.w3.org/2001/XMLSchema-instance’>soapenv:Bodycwmp:InformMikroTikE48D8ChAP ac…xxx0 BOOTSTRAP1 BOOT12020-09-02T13:54:43-06:000Device.RootDataModelVersion2.11Device.DeviceInfo.HardwareVersionv1.0Device.DeviceInfo.SoftwareVersion6.47.1Device.DeviceInfo.ProvisioningCodeDevice.ManagementServer.ParameterKeyDevice.ManagementServer.ConnectionRequestURLhttp://xxxx:7547/xxxxDevice.ManagementServer.AliasBasedAddressing0</cwmp:Inform></soapenv:Body></soapenv:Envelope>

This Mikrotik POST has nothing special. It is just an INFORM. Anyone has an idea on this?

Ok, I found my problem. I had a script with a typo or something.

Found helpful information going to mongodb and opening fault connection.

It was not a “crasher packet” (the packet from CPE was just an inform working ok) but GenieACS was trying to push a script everytime the device started a session and then crashed on that.

It would be nice if GenieACS would not crash though.

Since I’m still on development phase, my solution was just blasting all mongodb and restarting it again. This solved my problem. But if you are on production you may want to chase those scripts and tasks and kill them

After 2 weeks of struggling with this, I finally got a permanent solution. This has ABSOLUTELY NO RELATION TO THE PACKET SENT BY CPE. So it’s not that severe. I’m sorry about the post’s title.

I’m using
MongoDB version 4.4.0
GenieACS version 1.2.0
NodeJS version 12.18.3

I mentionned earlier that dropping the database (and I know now that, more specifically the operations collection) was “solving” my problem. But it kept coming back everytime I pushed a script to my MikroTik. After one operation existed for a specific device, anything from the same device (even an INFORM) would crash my cwmp service.

Here’s the exception stack
2020-09-14T17:07:47.829Z [ERROR] Uncaught exception; pid=31783 exceptionName=“SyntaxError” exceptionMessage=
“Unexpected token o in JSON at position 1” exceptionStack=“SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse ()
at getOperations (/home/genie/dist/bin/genieacs-cwmp:3961:27)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async Promise.all (index 2)
at async getDueTasksAndFaultsAndOperations (/home/genie/dist/bin/genieacs-cwmp:8499:18)
at async listenerAsync (/home/genie/dist/bin/genieacs-cwmp:8943:71)”
Sep 14 11:07:47 routeracs genieacs-cwmp[31768]: 2020-09-14T17:07:47.900Z [ERROR] Worker died; pid=31783 exitCode=0

I put a console.log( r ) around line 3961 on cwmp and find that the operations object from the MongoDB is already a JavaScript object and not a JSON sting, thus the JSON.parse(r.args) is throwing an exception that is not catched anywhere and crashes the service.

So I changed lib/db.ts to fix this
try{
if (r.args){
r.args = JSON.parse(r.args);
}
r.provisions = JSON.parse(r.provisions);
r.retries = JSON.parse(r.retries);
} catch (e){
//Dont panic, r.args is already javascript
} finally {
operations[commandKey] = r;
}

This fix the problem. I don’t know why anyone else had same problem yet, maybe I have a newer mongodb version with breaking changes? I don’t know. Anyways, will make a pull request on this because it should work.

I’m terribly sorry that you had to go through all that. I committed a fix for this issue just a few hours before your PR.

Thanks for the feedback. I already installed the latest version with your fix.