-
Notifications
You must be signed in to change notification settings - Fork 208
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
no event on connection loss #27
Comments
Looks like something to take a look at. Are you running in Node.js and/or a browser? If a browser, do you get the same behaviour on different browsers? |
Running in browser, tried Chrome and Firefox, getting same from both. |
Ok, thanks for the report. Going to look at this ASAP, probably tomorrow. Keeping the data fetched so far when the network fails is one of the major benefits of streaming. If we don't know when it goes down it makes impossible to request the bits that were missed. Pre-launch website example: |
Couple more questions. I'm trying to reproduce this in an integration test: What kind of server are you connecting to and how are you killing it? Do you get a fail event if you are in, say, jQuery and kill the server process? Cheers, |
Ok, I think jQuery will fail properly because of this: https://github.com/jquery/jquery/blob/master/src/ajax/xhr.js#L110 Easy bug to fix but not so easy to write an integration test for. Need to work out how to fake a network failure from a Node http server. |
Could you confirm if the xhrerror branch fixes the problem you're seeing? If this fixes it I'll merge into master and tag a new minor release. |
I am running it against django test server (Python WSGIServer) which I just kill using Ctrl-C in the middle of the response (the response is being generated slowly object by object so I have enough time to kill it). Unfortunately I still don't get the fail handler called upon the stream termination even with this branch. |
And yes, when trying ajax instead of oboe the fail() (or rather error() in case of ajax) handler gets called when the server is killed while generating the response. |
I've run quite a few experiments here and I'm seeing the Are you able to provide a stripped-down example of the failure? For example, with a server that gives a streaming JSON resource and a tiny webpage that uses jQuery and Oboe to fetch it. This would help a lot in diagnosing the problem. Alternatively, if you could get a failure in the unminified jQuery 2.0.3 and post a screenshot of a stack trace from inside the error handler so I can see where jQ is getting the failure from the underlying XHR, that'd help a lot too. From the code it looks like Oboe is catching all the failures that jQ is, but you must have found one that is slipping through somehow. Thanks for your help so far, |
Ok, I was trying to write a mini demo to show the issue using primitive http server based on python's Demo codeClient<html>
<body>
<script src="jquery.min.js"></script>
<script src="oboe-browser.min.js"></script>
<script>
$( document ).ready(function() {
oboe({
url: "http://localhost:8000",
})
.node('!.*', function (data) {
console.log('received: ' + data);
})
.done(function (data) {
console.log('done: ' + data);
})
.fail(function (error) {
console.log('fail: ' + error.thrown);
});
});
</script>
</body>
</html> ServerTested on linux, not sure how
#!/usr/bin/python
import BaseHTTPServer
import time
import os
import signal
class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_OPTIONS(self):
self.send_response(200)
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Access-Control-Allow-Headers', 'X-Requested-With')
self.end_headers()
def do_GET(self):
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.send_header('Access-Control-Allow-Origin', '*')
self.end_headers()
self.wfile.write('[\n')
self.wfile.write('[1,2,3],\n')
time.sleep(2)
# following line simulates termination between nodes (oboe's fail() miss)
# comment it out to simulate termination in middle of a node (fail() ok)
os.kill(os.getpid(), signal.SIGKILL)
self.wfile.write('[4,5')
os.kill(os.getpid(), signal.SIGKILL)
self.wfile.write(',6]\n]')
httpd = BaseHTTPServer.HTTPServer(
('localhost', 8000),
RequestHandler)
while True:
httpd.handle_request() ResultsIn first case (stream killed between nodes using the first
no error output from In second case (first
so |
This will be extremely useful, thank you. I'm on OSX which I'd guess is similar enough to Linux to reproduce the problem. If not I have a Linux box as well to run the server from. Going to take a look see what is happening inside Oboe. |
Still having problems reproducing the problem. I've found a related bug (but only in my branch, not master) where the .fail callback is called twice. Determined to squash this one though. Unfortunately I know almost no Python. How do I get the same server as is serving the streamed JSON to serve the HTML page so as to be able to hit it under the same-origin policy? At the moment I'm fronting your Python service with Apache mod_rewrite for the static HTML and I wonder if that is influencing the results. |
just load the html from disk using file://path/to/the/html and not from any server. if you don't run the python server on your localhost just change the listening address in the code to 0.0.0.0 and then the oboe url to whatever IP is the python running on. |
I mean point your browser to file://path/to/the/html |
re same-origin - the headers the server returns allow mixed origins for the sake of this demo... |
Ok, am now able to reproduce this problem. I can make some observations:
|
The good news is that because this issue is actually a JSON parsing problem (not a network issue) it is quite easy to write the automated test so that it doesn't come up again. |
Caught the bug in component tests here |
I've patched Clarinet now to fix this, if you want the fix quick let me know, you can build Oboe against my own version of Clarinet. I'm expecting to have a version of Oboe.js tagged without this bug perhaps next week. |
perfect, I can wait for the official release, thanks. |
Pull request into Clarinet: dscape/clarinet#20 |
Pull request was merged into Clarinet and this is fixed in Oboe.js as of v1.12.2 |
Hi,
The fail() handler is supposed to be called on connection loss but it doesn't seem so. I get it called ok for example when the connection couldn't establish at all but not when it is terminated in the middle of a stream.
For example I have a service the receives JSON array of IDs (using POST) and returns streamed JSON array of requested objects:
If I kill the service for example after receiving second object the fail() is not called and I have no way to handle that situation. This works ok if I run it when the service is already dead - the fail() handler gets called in this case.
Thanks, Antony.
The text was updated successfully, but these errors were encountered: