Skip to content
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

Remove default timeout on Sync #327

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions src/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ let EventTimeline = require("./models/event-timeline");

let DEBUG = true;

// /sync requests allow you to set a timeout= but the request may continue
// beyond that and wedge forever, so we need to track how long we are willing
// to keep open the connection. This constant is *ADDED* to the timeout= value
// to determine the max time we're willing to wait.
let BUFFER_PERIOD_MS = 80 * 1000;

function getFilterName(userId, suffix) {
// scope this on the user ID because people may login on many accounts
// and they all need to be stored!
Expand Down Expand Up @@ -152,17 +146,17 @@ SyncApi.prototype.syncLeftRooms = function() {
filter.setTimelineLimit(1);
filter.setIncludeLeaveRooms(true);

let localTimeoutMs = this.opts.pollTimeout + BUFFER_PERIOD_MS;
let qps = {
timeout: 0, // don't want to block since this is a single isolated req
var qps = {
timeout: 0 // don't want to block since this is a single isolated req
};

return client.getOrCreateFilter(
getFilterName(client.credentials.userId, "LEFT_ROOMS"), filter
).then(function(filterId) {
qps.filter = filterId;
// Don't set a timeout on Sync because there is no strategy to handle repeated timeouts on sync
return client._http.authedRequest(
undefined, "GET", "/sync", qps, undefined, localTimeoutMs
undefined, "GET", "/sync", qps, undefined, undefined
);
}).then(function(data) {
let leaveRooms = [];
Expand Down Expand Up @@ -507,11 +501,9 @@ SyncApi.prototype._sync = function(syncOptions) {
qps.timeout = 0;
}

// normal timeout= plus buffer time
let clientSideTimeoutMs = this.opts.pollTimeout + BUFFER_PERIOD_MS;

// Don't set a timeout on Sync because there is no strategy to handle repeated timeouts on sync
this._currentSyncRequest = client._http.authedRequest(
undefined, "GET", "/sync", qps, undefined, clientSideTimeoutMs
undefined, "GET", "/sync", qps, undefined, undefined
);

this._currentSyncRequest.done(function(data) {
Expand Down