HyperCatIoT / hc2-server

HyperCat 2.0 reference server
Apache License 2.0
5 stars 5 forks source link

hc server crash, invalid JSON should be handled #4

Open edgracilla opened 7 years ago

edgracilla commented 7 years ago

Got these logs from k8, please handle this error to avoid app crash

2017-04-25T15:32:19.140244565Z Waiting...Running "nodemon:dev" (nodemon) task 2017-04-25T15:32:19.176181258Z [nodemon] 1.11.0 2017-04-25T15:32:19.178688128Z [nodemon] to restart at any time, enter rs 2017-04-25T15:32:19.178990136Z [nodemon] watching: /home/node/hypercat-server/lib/*/ 2017-04-25T15:32:19.179661855Z [nodemon] starting node lib/main.js 2017-04-25T15:32:19.601526222Z Hypercat Reference daemon started on port 9090 2017-05-04T06:09:17.618404304Z undefined:1 2017-05-04T06:09:17.619451134Z 2017-05-04T06:09:17.619460034Z 2017-05-04T06:09:17.619462834Z 2017-05-04T06:09:17.619465634Z SyntaxError: Unexpected end of JSON input 2017-05-04T06:09:17.619468434Z at Object.parse (native) 2017-05-04T06:09:17.619471034Z at /home/node/hypercat-server/lib/hypercat/document.js:64:56 2017-05-04T06:09:17.619473934Z at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:446:3) 2017-05-04T06:09:17.622474620Z [nodemon] app crashed - waiting for file changes before starting... Logs from 4/25/17 3:32 PM to 5/4/17 6:09 AM

edgracilla commented 7 years ago

I created a small fix to handle this issue. I successfully catch the error but, I noticed that the real problem is the broken JSON file. Since it does not allow invalid json to be inserted, the first culprit that pops up into my mind is the writer.

I created a simple PoC to recreate the issue, ran it and confirmed that this hc server does not handle the parallel writes into file.

https://github.com/edgracilla/hc2-bomber-poc