penthouse: SyntaxError: Unexpected end of JSON input
Hi,
can you please help me to figure out what the problem is. It appears super randomly. But leads to break every 2nd/3rd build.
[09:23:20] Starting 'critical'...
caught err SyntaxError: Unexpected end of JSON input
at Object.parse (native)
at postformatting (/home/bbuhler/Dokumente/liita-client/node_modules/penthouse/lib/postformatting/index.js:25:28)
at /home/bbuhler/Dokumente/liita-client/node_modules/penthouse/lib/index.js:129:26
at ChildProcess.<anonymous> (/home/bbuhler/Dokumente/liita-client/node_modules/penthouse/lib/index.js:128:9)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
Fatal undefined
Process finished with exit code 2
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 40 (25 by maintainers)
Just an update that I can now reproduce this, and am looking into it.
This was a phantomJS specific issue; it is gone in #174, which uses Chrome headless. Will close when that PR is merged, should happen late this week.
Well, I can provide the Lambda function if you’d like to mess around with it on there. Unfortunately the native phantomjs code has to be precompiled, so I’m not sure if there would be problems in recompiling it while you make changes and test. It’s a slow process though. With phantom it’s almost 40 megs zipped, so it’s a change, upload, test, change, upload, test, kind of slowly.
The only thing that I can think of it being associated with is the events and, somehow, you’re putting out global events which are being caught by the other Penthouse process. The reason, I’d think, that it only happens some of the time is because that event listener on the other Penthouse process only happens to be associated at the same time as the original, thus throwing an unexpected end because the
criticalRules = JSON.parse(cssAstRulesJsonString)
isn’t ready to be called yet on the second process. If it’s sending the events out globally, as compared to only inside of some scope that Penthouse processes run in, then if some sort ofevent.on('foo')
was called simultaneously, or close to simultaneously, on two or more Penthouse functions, then when one finishes they all think they’re finished and call aJSON.parse
on an output that hasn’t yet finished constructing.I could also totally be off base and talking out my butt, but I have figured out a workaround which is to just not run the Penthouse processes concurrently in my code, instead running through them in series. Not a huge deal, but it’s kind of annoying and definitely increases my latency on each function by several seconds.
It must, therefore, be associated with parallel executions with Penthouse and, due to the stack trace containing an event call, I’d assume it has to do with two event listeners getting called in separate functions simultaneously.
Just my two cents. 😄