nowelium / socket.io-titanium

socket.io for titanium mobile
http://youtu.be/10ogNjWCpyc
Other
136 stars 34 forks source link

Socket.io-Titanium Causes App Crash on Distribution Build #10

Open allenhartwig opened 12 years ago

allenhartwig commented 12 years ago

Socket.io-Titanium has been working great for me, however, when I went to submit my app to iTunes Connect, I was rejected by Apple due to an app crash on launch. I never experienced this in my testing as Socket.io-Titanium works perfectly when building the app for non-distribution. However, when building the app for archive, then creating a distribution IPA and loading the IPA to a device, I am able to recreate the error.

Removing Socket.io-Titanium from the project causes the issue to be remedied.

The build methodology to recreate the problem can be found here: http://developer.apple.com/library/ios/#qa/qa1764/_index.html

The Crash Log is tracing back to: 10 APP NAME 0x0002990a KrollCallAsFunction (KrollMethod.m:70)

allenhartwig commented 12 years ago

The issue arises by just including Socket.io-Titanium. No connect call needs to be made.

Commenting out the following lines of socket.io-titanium.js causes the crash to go away:

    require('socket.io/lib/transports/xhr');
    require('socket.io/lib/transports/xhr-polling');
    require('socket.io/lib/socket');
joelongstreet commented 12 years ago

I'm also experiencing this issue when I publish AdHoc/Release builds. I've commented out the lines you've mentioned above but was unfortunately unable to get this to build successfully after a thorough clean.

After messing with this for a while, I'm suspicious that the issue has something to do with the naming conventions and the nested files within the socket.io module. I don't have any proof yet. I might mess with this a bit more and write a blog post if I get this figured out.

Thanks for your help @allenhartwig, was your app approved after you commented those lines out? Or were you able to verify release builds?

Besides this single issue, the plugin has been amazing. Thanks for your work @nowelium

allenhartwig commented 12 years ago

Commenting those lines out prevents the crash, yet renders socket.io useless. I had mentioned it only as a means to drill down on the cause, not suggesting a fix.

After further exploration, I agree with you: the bug has something to do with the socket.io module architecture. Appcelerator's commonjs framework is unable to properly handle it.

As to why it is occurring only in archive/distro builds is beyond me.

I have engaged Appcelerator support directly on this issue, but they have advised me support fees may be upwards of $12k to resolve. This issue is preventing me from submitting to the AppStore, putting me between a rock and a hard place.

Any ideas are welcome, and if you want to tag team this more aggressively, feel free to email me at Allen.hartwig@gmail.com.

joelongstreet commented 12 years ago

One strange thing I've noticed is that that socket.io folder MUST be named socket.io. Changing this folder's name and all respective pointers will result in unfound files. I wonder why this is? EDIT - because of this I suppose : http://iamwil.posterous.com/when-it-comes-to-titaniuminclude-its-a-trick

EDIT - it doesn't need to be named socket.io, but it needs to have a dot in the folder name. So hi.io/, temp.io/, somethingelse.io/ will all work. But sockets/ will not. Would a . in the folder name cause a fail the release build for Titanium?

joelongstreet commented 12 years ago

Well, I was thinking the . in the directory was for some reason confusing Titanium but that doesn't seem to be the case. I'm not sure what the issue might be now .... fuck ...

allenhartwig commented 12 years ago

Here is what I have found.

If you modify socket.js so it doesn't execute any code -- its just an empty module placeholder, and then comment out most of socket.io-titanium.js's functionality, it will still crash when including socket.js. Comment out the socket.js require line, and it loads fine (once again, not performing any functionality, but doesn't crash).

I have created a gist to demonstrate my changes here: https://gist.github.com/2466222

From what I can tell, there are no structural difference to how the socket.js module is constructed in comparison to the other module's requires. Also, there doesn't seem to be a maximum amount of requires you can perform, as I have tried including non socket.js modules into socket.io-titanium.js and it doesn't cause a crash.

Unfortunately, I don't know what is going on, but I thought this may help in your debugging.

allenhartwig commented 12 years ago

From what I can tell, the issue arises from passing this to the global argument in the self-firing function in socket.js, xhr.js, and xhr-polling.js.

I haven't found a work around yet, but this seems to be the common theme amongst the files causing the crash, and also explains why my gist above still causes the crash even when no code within the function is being executed.

allenhartwig commented 12 years ago

My previous suspicion was incorrect.

I haven't completely tested this, however, I think I have found the culprit.

Change + +new Date to + new Date in xhr.js and socket.js.

I'll follow up tonight after I've had a chance to ensure this is fixing the issue across the board.

allenhartwig commented 12 years ago

Ok, so change it to + new Date().getTime() and you should be good to go.

joelongstreet commented 12 years ago

O M G! I cannot believe that's all there was to it! How does the distributed code from socket.io even work? That's definitely a JS syntax error. You should write them about that.

allenhartwig commented 12 years ago

It is actually valid js. See this:

http://stackoverflow.com/questions/221539/what-does-the-plus-sign-do-in-return-new-date

Appcelerator's JavaScript interpreter seems to choke on it with distribution builds tho. I've brought this to their attention to figure out why test builds and distribution builds differ.

On Apr 23, 2012, at 8:45 AM, Joe Longstreetreply@reply.github.com wrote:

O M G! I cannot believe that's all there was to it! How does the distributed code from socket.io even work? That's definitely a JS syntax error. You should write them about that.


Reply to this email directly or view it on GitHub: https://github.com/nowelium/socket.io-titanium/issues/10#issuecomment-5284176

joelongstreet commented 12 years ago

That's amazing, I've never heard of the unary operator.

Is Appcelerator paying you in upwards of $12K for debugging their stuff?

allenhartwig commented 12 years ago

I'll invoice them and let you know how it turns out. ;)

soyoh commented 11 years ago

Hello! i was having the same error!! thanks that i've found this issue, @allenhartwig thanks for your solution! is weird on simulator and with development certificates it worked but with adhoc or distribution the app crash...

thanks, this "date" change just fixed the problem.