xhttp.send works once but fails the 2nd time - javascript

I have the following javascript that works happily the 1st time but fails the second time..
xhttp = new XMLHttpRequest();
xhttp.open("POST","FINDMOVES",false);
xhttp.send(text);
This send is actually being received by the server and a respone is written by the server. The server is my own and written in assembler.
The java console reports:-
POST http://localhost:1024/FINDMOVES net::ERR_EMPTY_RESPONSE
Uncaught DOMException: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://localhost:1024/FINDMOVES'.
This code works happily where it is used in other programs.
I am aware that:- "[Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience" but it is not java's decision as to what my end user experience is like. It is mine.
Anyone got any clues ??
further to this...(and some background)
I have a runtime module that acts as a web server. This is used to serve on-line programs and therefore be portable between windows/linux. It is statically linked to application programs.
I have a dozen application programs happily using this server.
I have 1 near identical application that is okay but it's "twin" progran is failing. I have been stepping through the programs for a couple of days now and I have noticed the following:-
The SYS_ACCEPT call returns the same file descriptor for all programs that work while in the failing program, after a few calls, it returns a different file descriptor and as soon as that is the case the web browser does not see the response (even though it was written without error)
Anyone know what's going on here ?

The answer to this is not what I would have expected and I came across it completely by accident when I commented out some file access in the application program to make the strace ouput clearer.
The application was at fault in that it opened a file in an initialisation section but mistakenly closed it each time it sent a response back to the server. It effect it opened once but closed many times. In some way this confused the linux kernel (?) and it was made evident in the SYS_ACCEPT call.
I have to admit, I do not understand why this occurs so if someone can shed some light on why this happens I would appreciate it. For now though it looks like everything is back to working again.
Oh, I was getting a -512 back from the SYS_ACCEPT call but could never find out what that represented. Perhaps it means "Hey dude, stop closing that bloody file" !!

Related

Why does React log to Chrome-Console "Content-script injection failed" (from allpages.js) when I never set up code to inject a script?

I am nearly done with my code for my new Website but am really bothered that the following gets somehow logged to my Chrome-Console:
For instance, it gets printed when I switch between pages of my Website (using react-router-dom). I am not consciously injecting any script (nor do I know how that would work or why I would do such a thing).
I don't even know what "allpages.js" is, I never came across it so far.
If I click on it, to see the area that throws the error, I get the following (it is on line 83):
Happy to provide any further info or code and thanks everyone!

XHR request from previous Capybara js spec surfacing (and failing) in next spec

We're using Chrome headless with Capybara and Selenium for three js feature tests.
We're having a predictable (only on CI) failure when one specific js test (using xhr) follows another which also uses xhr (see https://github.com/thredded/thredded/tree/separate-out-js-from-non-js-in-ci for the code or https://travis-ci.org/thredded/thredded/jobs/302376004 for a sample run).
The server error is always being surfaced in the next spec "User creates new topic with title and content" but the url is evidently from the previous spec "User replying to a topic starts a quote-reply (js)".
The obvious thing is that there is a race condition between a request that falls off the end of the spec and happens after DatabaseCleaner.clean. However, my understanding is that with Capybara 2.7+ [1] after_each should happen after a reset_session! which should prevent this precise problem. In any case I am pretty sure there is nothing in the page that could be creating this request (we have a specific wait/test for the completion of this ajax request).
This is happening with 3 different databases and 3 different rails versions (4.2, 5.0, 5.1).
We've upgraded to latest Capybara.
Have tried disabling turbolinks, adding in a massive (10s) sleep at the end of the offending spec... Have tried manually resetting sessions too.
Must be missing something. Any pointers?
[1] https://github.com/teamcapybara/capybara/pull/1637 referenced from https://bibwild.wordpress.com/2016/02/18/struggling-towards-reliable-capybara-javascript-testing/
UPDATE: Have added references to xhr, as another (new) js spec is having the problem, and that it isn't the first two requests (login form, and post to login) that is surfacing the error, but the first xhr request that surfaces the error. In the new case the xhr that is getting requested is being requested with POST in the subsequent spec even though it was originall requested with GET
Looks like it was a chromedriver bug.
We fixed this by upgrading chromedriver (on travis) to v2.33 (linux).
https://travis-ci.org/thredded/thredded/builds/302431113
The previous version was v2.31. Oddly we couldn't get this to break locally with 2.31 (mac).

Finding a strange Javascript function 'window.ueLogError' in a PhantomJS error message

I'm working on a project that involves retrieving multiple websites with PhantomJS and when I try to load Amazon.com, PhantomJS crashes while trying to evaluate this function with the error:
TypeError: 'undefined' is not a function (evaluating 'window.ueLogError')
The weird thing is that I can't seem to find any documentation or explanation of any kind for window.ueLogError. A google search gives a handful of websites with scripts that contain it, but it doesn't seem to be a part of any documentation I can find. Does anyone know anything about ueLogError?
The window object is the global sink in the browser. Every variable that you define globally (e.g. jQuery's $) is a property in window. ueLogError is not some kind of standardized JavaScript function. It is most likely some function for an advertisement script.
Not all resources that a page requests as part of the page load are actually successfully loaded. Some requests fail due to SSL problems. Some requests fail, because the user agent string is not supported. Some requests fail because of unknown reasons.
You can register to the onConsoleMessage, onError, onResourceError, onResourceTimeout events (Example) to see whether there are errors. Usually you will find that some JavaScript file wasn't loaded which would have contained ueLogError which another script depends on.

Unusual javascript HTTP caching / undefined issues

Ok. I have never seen anything like this before and I am quite confused... On a website I am working on, there are two JavaScript includes. (Well, many more, but the problem occurs with only two). We'll call these A.js and B.js.
A.js defines a JavaScript singleton A. Likewise B.js defines a JavaScript singleton B. The B class depends on methods from A.
I have almost all my code wrapped up in try { ... } catch { ... } blocks, and on error, the system generates an AJAX request to email me the details of the error.
On one system here in my office (Firefox 3.0 for Mac) I am seeing the strangest behavior. Once in a while, maybe once every hour or two, but with no specific pattern, I get an error email from class B: "ReferenceError: A is undefined."
I have no idea why/how A would be undefined sometimes. When I look in the apache logs, during the times I receive the error, the client is requesting /A.js, before requesting /B.js, and the server is responding with a 304 (Not Modified)
I somehow suspect the issue is that the file has expired from the client cache however the server doesnt send the file thus it is never executed and A is undefined. But that's just a guess and I don't understand why that would happen. And if I am guessing right, how do I fix it???
If it matters, mod_disk_cache was enabled on the server, and I have disabled it to see if that was causing the problem. If so, maybe this belongs on ServerFault...
Any suggestions very welcome!!
If you have the Webdevelopers toolbar installed in Firefox, activate "Disable Cache" it helps a lot on debugging.
start calling the first js function after! the page has loaded, do this by <body onload="startmyfunction()"> or similar.

Where in JavaScript is the request coming from?

I am debugging a large, complex web page that has a lot of JavaScript, JQuery, Ajax and so on. Somewhere in that code I am getting a rouge request (I think it is an empty img) that calls the root of the server. I know it is not in the html or the css and am pretty convinced that somewhere in the JavaScript code the reqest is being made, but I can't track it down. I am used to using firebug, VS and other debugging tools but am looking for some way to find out where this is executed - so that I can find the offending line amongst about 150 .js files.
Apart from putting in a gazzillion console outputs of 'you are now here', does anyone have suggestions for a debugging tool that could highlight where in Javascript requests to external resources are made? Any other ideas?
Step by step debugging will take ages - I have to be careful what I step into (jQuery source - yuk!) and I may miss the crucial moment
What about using the step-by-step script debugger in Firebug ?
I also think that could be a very interesting enhancement to Firebug, being able to add a breakpoint on AJAX calls.
You spoke of jQuery source...
Assuming the request goes through jQuery, put a debug statement in the jQuery source get() function, that kicks in if the URL is '/'. Maybe then you can tell from the call stack.
You can see all HTTP request done through JavaScript using the Firebug console.
If you want to track all HTTP requests manually, you can use this code:
$(document).bind('beforeSend', function(event, request, ajaxOptions)
{
// Will be called before every jQuery AJAX call
});
For more information, see jQuery documentation on AJAX events.
If its a HTTPRequest sent to a web server, I would recommend using TamperData plugin on Firefox. Just install the plugin, start tamper data, and every request sent will be prompted to tamper/continue/abort first.
Visit this page at Mozilla website
Just a guess here, but are you using ThickBox? It tries to load an image right at the start of the code.
First thing I would do is check whether this rouge request is an Ajax request or image load request via the Net panel in Firebug.
If it's Ajax, then you can overload the $.ajax function with your own and do a strack trace and include the URL requested before handing off to the original $.ajax.
If it's an image, it's not ideal, but if you can respond to the image request with a server side sleep (i.e. php file that just sleeps for 20 seconds) you might be able to hang the app and get a starting guess as to where the problem might be.

Categories

Resources