Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError __jsonpXX__ is not defined (on Android only) #506

Open
richardshergold opened this issue Oct 16, 2018 · 8 comments
Open

ReferenceError __jsonpXX__ is not defined (on Android only) #506

richardshergold opened this issue Oct 16, 2018 · 8 comments

Comments

@richardshergold
Copy link

richardshergold commented Oct 16, 2018

I'm using the FAYE library in an Ionic Framework project (Cordova) and have it running successfully on both iOS and Android. However, on Android I sometimes get the following errors logged to my back-end crash reporting system (sentry.io):

ReferenceError __jsonpXX__ is not defined

where XX could be any number and is always different.

Looking at my logs it appears these errors ONLY occur when the FAYE connection has gone offline (the FAYE connection seems to continuously go online and offline - is this usual?). When I say on/offline I just mean that I write a console log on transport up or transport down. I am guessing that because it only ever seems to happen at a time FAYE is offline that these errors are being generated by FAYE - is that the case? If so, is there a recommended way of stopping them from occurring?

thanks

@jcoglan
Copy link
Collaborator

jcoglan commented Jun 11, 2019

The JSON-P transport works by defining a function named __jsonpXX__ and then injecting a <script> tag to make the request to the server, which will generate a JavaScript payload that invokes the given function with the response data, i.e. __jsonpXX__(response). If you're seeing these errors it means those scripts are arriving but the function they're calling is no longer defined.

This could mean two things. First, the function was never defined. This should not be the case as the <script> is injected after the callback function is defined, here:

global[callbackName] = function(replies) {
cleanup();
self._receive(replies);
};
script.type = 'text/javascript';
script.src = URI.stringify(endpoint);
head.appendChild(script);

Or, it means the function has been removed by the time the script loads. This could happen as failure detection in JSON-P is not reliable, and so we mostly rely on timeouts. The client tells the dispatcher to apply a timeout to each message it sends here:

faye/src/protocol/client.js

Lines 320 to 328 in 45a1731

var timeout = this._advice.timeout
? 1.2 * this._advice.timeout / 1000
: 1.2 * this._dispatcher.retry;
this.pipeThroughExtensions('outgoing', message, null, function(message) {
if (!message) return;
if (callback) this._responseCallbacks[message.id] = [callback, context];
this._dispatcher.sendMessage(message, timeout, options || {});
}, this);

If the outgoing message has an advice.timeout field, the timeout is 1.2 times that amount, otherwise it's 1.2 times the dispatcher's default retry timeout, which is 5 seconds. If your app is suffering from high latency, those timeouts may trigger even though the server is responding, causing the __jsonpXX__ function to be removed as part of the JSON-P request cleanup process.

It would be worth adjusting these timeouts and seeing if they improve things for your application.

@jcoglan
Copy link
Collaborator

jcoglan commented Feb 14, 2020

Hi @richardshergold, did you manage to investigate this issue further?

@richardshergold
Copy link
Author

@jcoglan no! we get these errors a lot but only from Android devices. No idea why they occur and what we could do to stop them. If you know any more, please share!

@jcoglan
Copy link
Collaborator

jcoglan commented Feb 14, 2020

My only guess is that this is a latency problem and the functions are being removed before the server response arrives. You could try deleting these lines and see if that makes a difference:

global[callbackName] = undefined;
try { delete global[callbackName] } catch (error) {}

If it does, then we could add a delay to this clean-up to allow the server more time to respond. Although after the timeout that calls cleanup(), the client proceeds on the assumption the response never arrived, so we should probably switch these callbacks out for ones that just ignore their input. At least then you won't get exceptions...

@richardshergold
Copy link
Author

@jcoglan thanks - I will try that although it won't be for another week or so until I get onto it.

@jcoglan
Copy link
Collaborator

jcoglan commented May 22, 2020

Hi @richardshergold, did you manage to make any progress with this issue?

@richardkshergold
Copy link

@jcoglan I'm really sorry I have not got round to trying out your suggestion - I will make a note to try this soon and promise to get back to you. Thanks!

@ioev
Copy link

ioev commented Jun 30, 2020

Just wanted to chime in and mention that I'm seeing these errors as well. We have an application that is available on an internal network, and also over a vpn appliance. 100% of the errors we are seeing are through this vpn, and 99.9% are on mobile (there are just a very few Windows 10/Chrome machines.) Users are typically using mobile when accessing through the vpn so this makes sense. It would be very unlikely for non-vpn users to be using mobile, so it's hard to determine if this is related to mobile browsers or due to the vpn.

The two errors we see are:
Uncaught ReferenceError: jsonp4 is not defined
ReferenceError: Can't find variable: jsonp8

The number of course varies, and in one particular case we've seen it over 200 with most of the errors occurring within the same second for the same user, so I don't think this is related to a timeout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants