Skip to content

Timeout errors aren't handled sanely #40

Closed

Description

@dgoldstein0

setup:
anonymous AMD module accessible at /static/compiled/js/tests/fixtures/test_module.js. Doesn't matter what it exports.

var req = requirejs.config({
  context: "foobar",
  baseUrl: "/static/",
  paths: {"tests/fixtures/test_module": "compiled/js/tests/fixtures/test_module"},
  waitSeconds: .00001,
})
req.onError = function(e){console.log("local require error", e)};
req(
  ["tests/fixtures/test_module"],
  (a) => console.log("failed.  loaded:", a),
  (err) => console.log("success", err)
);

Expect: errback to fire; success callback not to fire. window.onError / requirejs.onError / req.onError not to fire (as the errback will have handled things)

Actual (Tested in Chrome 61): the timeout is thrown, and caught by req.onError (Uncaught Error: Timeout for modules: tests/fixtures/test_module). The success callback is called regardless, and with the correctly loaded module (in this synthetic case of absurdly low timeout + working server). I wonder if the success callback would be called if the timeout was actually long enough that the browser itself gave up.

And for bonus points: the following results in two timeouts, but the second has no modules attached: Uncaught Error: Timeout for modules : is the error message.

var req = requirejs.config({
  context: "foobar",
  baseUrl: "/static/",
  paths: {"tests/fixtures/test_module": "compiled/js/tests/fixtures/test_module"},
  waitSeconds: .00001,
})
req.onError = function(e){console.log("local require error", e)};
req(
  ["tests/fixtures/test_module"],
  (a) => console.log("failed.  loaded:", a),
  (err) => console.log("success", err)
);
req(
  ["tests/fixtures/test_module"],
  (a) => console.log("failed.  loaded:", a),
  (err) => console.log("success", err)
);

Activity

  1. dgoldstein0 commented on Oct 30, 2017

    @dgoldstein0
    Author

    relatedly - I was doing more experimentation and it appears that timeouts apply in some way even to modules that are already loaded - e.g. if a timeout is too short, you can't require(["foo"]) even if "foo" is already loaded in the context. I don't really understand the full nature of what was going on though so not totally sure if my interpretation is correct - but basically what I tried was loading my error reporting code async in req.onError and that got unhappy fast with the short timeout.

  2. jrburke commented on Nov 22, 2017

    @jrburke
    Member

    Timeout reporting should work better now that #41 has landed. Thanks for outlining the issue. I was able to use the above code sample to construct a test.

    As for the super short timeout (like .0001) causing an error even for something already loaded in the context, I expect the issue is that the internally the code processing, with an async promise resolution, needs to finish before the timeout expires. With a super short timeout, that basic setup work will not finish in time and the first check() call errors things out with timeouts.

    I did not fully trace that though as I do not expect timeouts on the order of 1ms to be desirable for real use cases.

  3. dgoldstein0 commented on Nov 23, 2017

    @dgoldstein0
    Author

    As for the super short timeout (like .0001) causing an error even for something already loaded in the context, I expect the issue is that the internally the code processing, with an async promise resolution, needs to finish before the timeout expires. With a super short timeout, that basic setup work will not finish in time and the first check() call errors things out with timeouts.

    I believe my promise polyfillshould actually be using microtasks... so it's possible I should expect promises to resolve quick enough? Though I suppose that's only if the promise resolves immediately... perhaps we aren't in that case.

    I did not fully trace that though as I do not expect timeouts on the order of 1ms to be desirable for real use cases.

    that's totally fair. I used this as an artificial way of forcing the timeout behavior just to test how it behaved.

    Thanks for the fix, btw. Hopefully after the holiday I'll have some time to take it for a spin.

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