Thread related error on ofxLibwebsockets

Hey, I’ve just seen a very strange bug that may be related to this.

I’m currently sending a json formated text through websockets to the client. The client is a web app. There I merge the json I just sent to a json that represents the current state of the application.

On the Javascript console I’ve constantly getting this: (since I started using ofxLibwebsockets)

Uncaught SyntaxError: Unexpected token x

Where x can be any character.
Because it didn’t seem to effect the functioning of the app I haven’t tried to fix it yet.
The error points to an unexisting line on the main html file, I believe its because I’m using AngularJs and some how it gets ofuscated.

So, on my last try, one of the attributes of the merged Json got “duplicated” a few times.

The json is created using ofxJson and the attribute name is not generated dynmically or anything.

Could it be possible that ofxLibwebsockets its failing to concatenate or split the different messages it sends?
In some cases it corrupts the Json and that’s why I’ve been getting Uncaught SyntaxError, but in other cases the json stills valid but its content gets messed up.

@xavivives OK, pushed up some more cleanup. It does look like you’re hitting a weird race condition.

There’s a bigger issue I need to tackle, which is handling larger many-to-one messages. The way it’s architected now, I don’t think you can blast out massive messages to all of your connections successfully. Looking at that now.

Otherwise, it should be a bit better. I tested sending ~1 MB of JSON at 60 fps and should be OK. My example is only sending in update, so that should prevent any race conditions. I moved from a vector to a dequeue which may help as well.

Keep testing, we’ll figure this out!

One more update: fixed one-to-many sending in latest push. Should be better in general!

Seems the same previous bug is back (tested on server_echo)

In my app, If I keep trying to reconnect, after few seconds it crashes on ibsystem_pthread.dylib
I’m actually just broadcasting to a single connection.
I’m on a 2011 Macbook Air. With a new iMac I was unable to reproduce the bug. Will do new testing on the iMac.

@xavivives OK! Another fix. No longer passing messages around as references, which should help all of your problems.

I was getting the same crash (though only in Xcode, not outside), and that fixed it. Keep on testing. Glad to have someone making sure the addon is water-tight!

Woah! @robotconscience, your latest changes seem they did the trick!
I’ve been running it for over 8h at +60fps and eventually with multiple connections and it hasn’t crashed a single time! I’ll keep pushing… :grin:

Glad I can be useful. I was feeling more like I was being a pain in the ass… ^^"
ofxLibwebsockets has become a key part on the software I’m building. It allows me to “outsource” the nonexistent OF’s ui to a web based interface. So, Is good to know I have this amazing support!
Currently I’m targeting Mac but should expand to other platforms soon, If there is anything else that comes up I’m going to notice it!

Thanks a lot for your time and effort!!!