title: Why is my firebase transaction expired or no longer valid?
body: <p>I’m looking for some help on how to use transactions in my firebase/angular 6 application.</p>
  
  <p>I have this:</p>
  
  <pre><code>    let transactionResult;
      try {
          transactionResult = await db.runTransaction(trans =&gt; {
              console.log('running transaction');
              const result = trans.commit();
              console.log('result =', result);
              return result;
          });
      } catch (err) {
          console.log('catching error; err =', err);
      }
      console.log('transactionResult =', transactionResult);
  </code></pre>
  
  <p>I get this for output:</p>
  
  <pre><code>running transaction
  info: result = Promise { &lt;pending&gt; }
  info: catching error; err = { Error: 10 ABORTED: The referenced transaction has expired or is no longer valid.
  at Object.exports.createStatusError (/Users/gibranshah/repos/EVABlockchain/functions/node_modules/firebase-admin/node_modules/grpc/src/common.js:87:15)
  at Object.onReceiveStatus (/Users/gibranshah/repos/EVABlockchain/functions/node_modules/firebase-admin/node_modules/grpc/src/client_interceptors.js:1188:28)
  at InterceptingListener._callNext (/Users/gibranshah/repos/EVABlockchain/functions/node_modules/firebase-admin/node_modules/grpc/src/client_interceptors.js:564:42)
  at InterceptingListener.onReceiveStatus (/Users/gibranshah/repos/EVABlockchain/functions/node_modules/firebase-admin/node_modules/grpc/src/client_interceptors.js:614:8)
  at callback (/Users/gibranshah/repos/EVABlockchain/functions/node_modules/firebase-admin/node_modules/grpc/src/client_interceptors.js:841:24)
  code: 10,
  metadata: Metadata { _internal_repr: {} },
  details: 'The referenced transaction has expired or is no longer valid.',
  note: 'Exception occurred in retry method that was not classified as transient' }
  </code></pre>
  
  <p>I’m not familiar with how transactions work so I don’t know what it means that “The referenced transaction has expired or is no longer valid.” or “Exception occurred in retry method that was not classified as transient”. 
  I’m trying to run as simple a transaction as possible. So I run commit() and return the results. That’s it. I would think that would be simple enough to work.</p>
  
  <p>If I don’t do anything in the transaction as follows:</p>
  
  <pre><code>        transactionResult = await db.runTransaction(trans =&gt; {
              console.log('running transaction');
          });
  </code></pre>
  
  <p>I get this:</p>
  
  <pre><code>info: running transaction
  info: catching error; err = Error: You must return a Promise in your transaction()-callback.
  at transaction.begin.then (/Users/gibranshah/repos/EVABlockchain/functions/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/index.js:494:32)
  at &lt;anonymous&gt;
  </code></pre>
  
  <p>If I return a resolved promise as follows:</p>
  
  <pre><code>        transactionResult = await db.runTransaction(trans =&gt; {
              console.log('running transaction');
              return Promise.resolve();
          });
  </code></pre>
  
  <p>I get this:</p>
  
  <pre><code>info: running transaction
  info: running transaction
  info: running transaction
  info: running transaction
  info: running transaction
  info: catching error; err = TypeError: Cannot read property 'seconds' of null
  at Function.fromProto (/Users/gibranshah/repos/EVABlockchain/functions/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/timestamp.js:91:47)
  at _firestore.request.then.resp (/Users/gibranshah/repos/EVABlockchain/functions/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/write-batch.js:472:42)
  at &lt;anonymous&gt;
  </code></pre>
  
  <p>It seems to repeatedly run the transaction until it tries to read ‘seconds’ from a null object.</p>
  
  <p>What is the simplest transaction I can write that will work?</p>