Skip to content

Client tracker does not process aboting his 'pullCallbacks' requests #5

Open

Description

@AnotherOneAckap

Steps to reproduce:
1.Open http://astrojs.github.io/sampjs/examples/monitor.html and connect it to hub
2.Add to page HTML with devtools or script this link

<a href="javascript:void(document.location='http://aladin.u-strasbg.fr/java/nph-aladin.pl?frame=get&id=AladinBeta.jnlp');">launch Aladin</a>

3.Click on added link
Result: Aladin is started, but client tracker does not show it in list.
Cause: Request 'pullCallbacks' was cancelled by browser. but samp XmlRpcClient does not have 'onabort' handler and can't recover.

I suggest to patch it like this, but not sure about different implementations of Xhr used in samp.js

diff --git a/samp.js b/samp.js
index a621029..33b0aa9 100644
--- a/samp.js
+++ b/samp.js
@@ -591,6 +591,9 @@ var samp = (function() {
                     errHandler(event);
                 }
             };
+            xhr.xhr.onabort = function(event) {
+              xhr.onerror(event);
+            };
             xhr.send(req.toXml());
             return xhr;
         })(this);

Activity

  1. mbtaylor commented on May 12, 2014

    @mbtaylor
    Member

    @AnotherOneAckap, I'm having trouble reproducing this - mostly the list updates correctly for me, though I think I did see the failure happen once. Unfortunately, I write javascript just infrequently enough that I forget it all between times, so I'm not totally on top of what's going on here.

    There's at least a couple of things I don't understand. Can you explain in more detail what goes wrong as the result of the lack of an abort handler? I've written in the comments that abort is ignored, which I thought was reasonable, but if it's causing trouble clearly it needs a fix. Secondly, your suggested fix above says xhr.xhr.onabort - is that what you mean, or should it just be xhr.onabort? It looks to me that something like xhr.onabort = xhr.onerror might do the trick, but I still don't fully understand the problem.

  2. AnotherOneAckap commented on Jun 21, 2014

    @AnotherOneAckap
    ContributorAuthor

    @mbtaylor, You can see bug in action on http://ocl.sai.msu.ru/
    1.Use menu in left top corner to connect to hub. (I used Google Chrome Version 35.0.1916.153)
    2.Try to "launch Aladin"
    3.Link "Launch Aladin" must change to aladin icon. (And client list does not refresh anymore)
    Refresh page to remove glitch.

    Second, "xhr.xhr.onabort" is that what I meant, cause samp.js

    Creates an XHR facade - an object that presents an interface
    resembling that of an XMLHttpRequest Level 2.
    This facade may be based on an actual XMLHttpRequest Level 2 object
    (on browsers that support it), or it may fake one using other
    available technology.

    So we must find onabort handler for all possible cases of this facade:

    1. Based on XMLHttpRequest-type ( that what I wrote about )
    2. Based on XDomainRequest
    3. Based on Flash/flXHR
      Also abort is not error, so we can't just say "xhr.onabort = xhr.onerror", this decision must make developer, based on his task.
  3. mbtaylor commented on Jun 23, 2014

    @mbtaylor
    Member

    @AnotherOneAckap , if xhr.xhr.onabort is what you meant, then from your fix it looks like the problem was the XMLHttpRequest Level 2 object lacking an onabort method, not as you said to start with the XmlRpcClient. That makes a bit more sense to me, is it what you meant?

    If that's right, then adding an onabort method to the XMLHttpRequest object when the XHR facade is created would be cleaner than patching it up in the facade. Something like:

    diff --git a/samp.js b/samp.js
    --- a/samp.js
    +++ b/samp.js
    @@ -438,6 +438,16 @@ var samp = (function() {
                         }
                     };
                 })(this);
    +            xhr.onabort = (function(l2) {
    +                return function(event) {
    +                    if (!l2.completed) {
    +                        l2.completed = true;
    +                        if (l2.onerror) {
    +                            l2.onerror("abort");
    +                        }
    +                    }
    +                };
    +            })(this);
             };
    

    XDomainRequest has no documented onabort method so I think it can be ignored for this purpose, and the flXHR implementation is supposed to behave just like XMLHttpRequest (and uses the same code in samp.js) so should not need any special handling. I think this change would be harmless.

    Does it fix the problem for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions