title: Firebase transaction “maxretry”
body: <p>Wasted 3 hours already - trying to run transaction in firebase but it always fails with maxretry.</p>
  
  <p>Basically my flow is:</p>
  
  <p>On client:</p>
  
  <ol>
  <li>call firebase http cloud funciton using js sdk.</li>
  </ol>
  
  <p>On server:</p>
  
  <ol start="2">
  <li>read data from data base</li>
  <li>update/invalidate data if needed</li>
  <li>write the data back using transaction</li>
  </ol>
  
  <p>The problem - step 4 always fail with maxretry.</p>
  
  <p>The simplified code:</p>
  
  <pre><code>exports.myMethod2 = functions.https.onCall((data, context) =&gt; {
      utilsModule.throwIfNoAuth(context);
      return methodWithTransaction(context, admin);
  });
  
  exports.methodWithTransaction = function (context, admin) {
      //this is called only once from outside!
      return rootRef.child("my/data/path").once("value")
          .then(function (indexRef) {
              var usageObj = indexRef.val();
              //update object's state
              usageObj =
                  {
                      timestampUtcArray: [1530656089821, 1530656089822],
                      itemsCount: 2,
                      writeTimestamp: 1530656502759
                  }
              return usageObj;
          })
          .then(function (usageObj) {
              //her eis the sad part...
              return rootRef.child("my/data/path").transaction(data =&gt; {
                  //this method always run 25 times and fails.
                  //data aways != usageObj though accross the calls usageObj are the same as well data are the same:
                  // usageObj =
                  //     {
                  //         timestampUtcArray: [1530656089821, 1530656089822],
                  //         itemsCount: 2,
                  //         writeTimestamp: 1530656502759 &lt;-- only timestamp is different
                  //     }
                  // data =
                  //     {
                  //         timestampUtcArray: [1530656089821, 1530656089822],
                  //         itemsCount: 2,
                  //         writeTimestamp: 1530656503421 &lt;-- only timestamp is different
                  //     }
  
                  return usageObj;
              }
          })
  
  }
  </code></pre>
  
  <p>Any input s much appreciated as this seems to be a trivial task but I just stuck...</p>