Skip to content

Use the provided timeout option, if set, for the InfoReceiver. ⏰ #594

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

tomconnell-wf
Copy link

We have some users with truly terrible internet connections. From time to time, the InfoReceiver times out for them. We'd like to be able to configure a longer timeout for the InfoReceiver, instead of the hardcoded 8000ms.

This PR accomplishes this. However, I haven't used javascript for years, and am a little uncertain if there is a simple and reliable way to unit test the addition of this configurable timeout. I'd be happy to figure it out if given some guidance.

I'm also unsure if I should build dist/sockjs for the PR and if so, how to do it.

@tomconnell-wf
Copy link
Author

var self = this
, url = urlUtils.addPath(baseUrl, '/info')
;
debug('doXhr', url);

this.xo = InfoReceiver._getReceiver(baseUrl, url, urlInfo);

if (timeout === undefined) {
timeout = InfoReceiver.timeout
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I saw in the documentation that SockJS will use the bigger timeout of either the "internally calculated" timeout, or the timeout option. Do you want this to apply here, too? Something like

if (timeout < InfoReceiver.timeout) {
  timeout = InfoReceiver.timeout
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not really "calculated," though. 😉

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

timeout (number)

Specify a minimum timeout in milliseconds to use for the transport connections. By default this is dynamically calculated based on the measured RTT and the number of expected round trips. This setting will establish a minimum, but if the calculated timeout is higher, that will be used.

@tomconnell-wf
Copy link
Author

@brycekahle - You look like the person running the repo, if you would be so kind as to review this.

Comment on lines +292 to +330
describe('info', function () {
it('will timeout - default timeout', function (done) {
this.timeout(10000);
InfoReceiver.prototype._getReceiver = function(baseUrl, url) {
return new InfoAjax(url, XhrFake);
};

var expectedWasClean = true;
InfoReceiver.prototype._cleanup = function(wasClean) {
expect(wasClean).to.equal(expectedWasClean);
if (expectedWasClean === false) {
// Cleanup was called because of a timeout
done();
}
expectedWasClean = false;
};

new InfoReceiver('test', {});
});

it('will timeout - configured timeout', function (done) {
this.timeout(2000);
InfoReceiver.prototype._getReceiver = function(baseUrl, url) {
return new InfoAjax(url, XhrFake);
};

var expectedWasClean = true;
InfoReceiver.prototype._cleanup = function(wasClean) {
expect(wasClean).to.equal(expectedWasClean);
if (expectedWasClean === false) {
// Cleanup was called because of a timeout
done();
}
expectedWasClean = false;
};

new InfoReceiver('test', {}, 1000);
});
});
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I apologize for these awkward tests - I do not fully understand all of the inheritance going on, so I overrode what I needed to test the override. The result is that the finish event is still emitted, and that is why I have the wasClean expectation change.

Copy link
Member

@auvipy auvipy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please fix the merge conflict and make it easier to review?

@auvipy auvipy requested a review from Copilot August 7, 2025 06:30
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enables configurable timeout for the InfoReceiver to support users with poor internet connections, replacing the hardcoded 8000ms timeout with an optional user-provided value.

  • Added timeout parameter to InfoReceiver constructor and doXhr method
  • Modified SockJS main class to pass options.timeout to InfoReceiver
  • Added unit tests to verify timeout functionality with both default and custom timeout values

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
lib/info-receiver.js Added timeout parameter support with fallback to default timeout
lib/main.js Modified to pass options.timeout to InfoReceiver constructor
tests/lib/receivers.js Added test cases for default and configured timeout scenarios

@@ -121,7 +121,7 @@ function SockJS(url, protocols, options) {
, sameScheme: urlUtils.isSchemeEqual(this.url, loc.href)
};

this._ir = new InfoReceiver(this.url, this._urlInfo);
this._ir = new InfoReceiver(this.url, this._urlInfo, options.timeout);
Copy link
Preview

Copilot AI Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential runtime error if 'options' is undefined or null. The code should safely access options.timeout with optional chaining or a fallback check.

Copilot uses AI. Check for mistakes.

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

Successfully merging this pull request may close these issues.

2 participants