tusResumeUpload returns without throwing when every resume attempt fails, so the attachment upload is treated as complete

Author: 3mmmbulusCreated Sep 30, 2026Updated Sep 30, 2026

Overall summary

tusResumeUpload returns normally, without throwing, when it runs out of retries without ever completing the upload. If the create-with-upload request fails at the transport level and then every resume PATCH also fails at the transport level, tusUpload resolves and the caller treats the attachment as uploaded.

I found this by reading the code and confirmed it with a unit-level reproduction against the unmodified source (below). I have not seen it happen in a released build, so the real-world impact described here is inferred from the code, not from a user-visible failure.

Where it happens

All links are to main @ abe80d3.

  • _tusResumeUploadRequest returns false (instead of throwing) when the PATCH dies at the transport level, "closed without response": tusProtocol.node.ts L265-L269.
  • tusResumeUpload loops up to maxRetries (default 3) times, doing a HEAD for the current offset and then that PATCH. The loop only exits early through break: when HEAD reports offset === fileSize, or when the PATCH returned true (L374-L410). If every round returns false, the while ends and the function falls off the end at L411 without throwing.
  • tusUpload only calls tusResumeUpload when the initial create-with-upload returned false (L320-L321) and does nothing with the outcome besides awaiting it.
  • Caller: encryptAndUploadAttachment awaits uploadFile → tusUpload and, once that resolves, returns { cdnKey, cdnNumber, encrypted }; its finally then deletes the local ciphertext (uploadAttachment.preload.ts L184-L206). uploadAttachment then builds the descriptor (cdnKey, key, digest, ...) that goes into the message. The uploadType: 'backup' branch shares the same uploadFile call.

Steps to reproduce

Unit level, no app needed. Give tusUpload a fake fetchFn where HEAD answers Upload-Offset: 0 and POST/PATCH reject the way a dropped connection does. Abridged from a mocha test I ran in ts/test-node (with sinon fake timers so the 1 s + 2 s + 3 s backoff between rounds doesn't take real time):

typescript
const calls: Array<string> = [];
const fetchFn = async (_url, init) => {
  calls.push(init.method);
  if (init.method === 'HEAD') {
    return new Response(undefined, {
      status: 200,
      headers: { 'Upload-Offset': '0' },
    });
  }
  throw new Error('socket hang up'); // POST and PATCH die at the transport level
};

await tusUpload({
  endpoint: 'https://cdn.example.test/upload/attachments',
  headers: {},
  fileName: 'key',
  filePath: 'path',
  fileSize: 6,
  reader: () => Readable.from([Buffer.from('abcdef')]),
  fetchFn,
});
// resolves

Expected result

tusUpload rejects once the retries are used up, so uploadFile and encryptAndUploadAttachment throw and the send fails (or is retried) instead of carrying on.

Actual result

tusUpload resolves. Requests seen by the fake: POST, HEAD, PATCH, HEAD, PATCH, HEAD, PATCH, and not a byte was accepted.

By the code above, the caller would then return a cdnKey/digest for an object that was never (fully) uploaded, delete the local ciphertext, and the message would go out referencing it. I'd expect recipients to fail to download it or fail the digest check, but that part is inferred, not tested.

This needs HEAD to keep succeeding while the create request and all three PATCH bodies die in flight. I haven't assessed how likely that is in practice; a connection that handles small requests but repeatedly drops a large upload body is the obvious candidate.

Suggested fix

Return from the loop when the upload is known to be complete, and throw once the loop is exhausted:

diff
     if (uploadOffset === fileSize) {
-      break;
+      return;
     }
 ...
     if (done) {
-      break;
+      return;
     }
   }
+
+  throw new Error(`tusProtocol: upload incomplete after ${maxRetries} attempts`);
 }

I have tests for this with a fake fetchFn (all PATCHes fail → rejects; one failure then success → resolves; HEAD already at fileSize → resolves without a PATCH).

Signal version

Source review of main @ abe80d3 (2026-09-23). ts/util/uploads/tusProtocol.node.ts is byte-identical at v8.27.0. Not tested in a released build.

Operating system

n/a (logic bug). Reproduced with node unit tests on macOS, Node 24.17.0.

Version of Signal on your phone

n/a

Link to debug log

n/a

Source: signalapp/Signal-Desktop