Bug 1401686 - Handle cases where max_post_bytes is less than max_record_payload_bytes. r?markh draft
authorThom Chiovoloni <tchiovoloni@mozilla.com>
Wed, 20 Sep 2017 16:18:20 -0400
changeset 667827 a37c02f70fcc87f5c87d10a71f89bce60a112082
parent 667826 7e16f505b25f498935afa0dbc893cb9eef2d1207
child 732528 6fbce2da95a7719ba3df81be25b5d4186567a447
push id80864
push userbmo:tchiovoloni@mozilla.com
push dateWed, 20 Sep 2017 20:20:06 +0000
reviewersmarkh
bugs1401686
milestone57.0a1
Bug 1401686 - Handle cases where max_post_bytes is less than max_record_payload_bytes. r?markh MozReview-Commit-ID: AAiF2rD075A
services/sync/modules/record.js
services/sync/modules/service.js
--- a/services/sync/modules/record.js
+++ b/services/sync/modules/record.js
@@ -814,18 +814,19 @@ Collection.prototype = {
       max_post_records: getConfig("max_post_records", Infinity),
 
       max_batch_bytes: getConfig("max_total_bytes", Infinity),
       max_batch_records: getConfig("max_total_records", Infinity),
       max_record_payload_bytes: getConfig("max_record_payload_bytes", 256 * 1024),
     };
 
     if (config.max_post_bytes <= config.max_record_payload_bytes) {
-      this._log.error("Server configuration max_post_bytes is too low", config);
-      throw new Error("Server configuration max_post_bytes is too low");
+      this._log.warn("Server configuration max_post_bytes is too low for max_record_payload_bytes", config);
+      // Assume 4k of extra is enough. See also getMaxRecordPayloadSize in service.js
+      config.max_record_payload_bytes = config.max_post_bytes - 4096;
     }
 
     this._log.trace("new PostQueue created with config", config);
     return new PostQueue(poster, timestamp, config, log, postCallback);
   },
 };
 
 /* A helper to manage the posting of records while respecting the various
--- a/services/sync/modules/service.js
+++ b/services/sync/modules/service.js
@@ -620,17 +620,21 @@ Sync11Service.prototype = {
 
   getMaxRecordPayloadSize() {
     let config = this.serverConfiguration;
     if (!config || !config.max_record_payload_bytes) {
       this._log.warn("No config or incomplete config in getMaxRecordPayloadSize."
                      + " Are we running tests?");
       return 256 * 1024;
     }
-    return config.max_record_payload_bytes;
+    let payloadMax = config.max_record_payload_bytes;
+    if (config.max_post_bytes && payloadMax <= config.max_post_bytes) {
+      return config.max_post_bytes - 4096;
+    }
+    return payloadMax;
   },
 
   async verifyLogin(allow40XRecovery = true) {
     if (!this.identity.username) {
       this._log.warn("No username in verifyLogin.");
       this.status.login = LOGIN_FAILED_NO_USERNAME;
       return false;
     }