Photo uploads randomly failing on Android, and a Chrome bug

For a few days, uploading photos from my phone to the new SunPhoto site kept failing. Not all of them. I would pick 4 photos and 1 or 3 of them would fail, a different one each time. Retry didn’t help, but picking the same photo again worked.

The old site uploaded the exact same photos without any problem.

The error from Chrome was this:

It had nothing to do with permissions, as I found out later.

The setup

The old PHP site and the new one (Symfony + React) run side by side while the new one takes over. Deploying is just a push to main, and production picks it up in about a minute, so I could try a new version on the phone almost right away. We went through eight of them in a bit over an hour.

The new upload dialog shows a preview for every picked photo, then uploads the originals one by one. The previews were simple <img> tags with URL.createObjectURL(file), all created right after picking.

The old uploader (plupload) has no previews. It reads a photo only when its turn comes, resizes it in the browser and sends it.

I was testing on a Pixel 9 Pro XL, with Chrome, Google’s photo picker, and photos I had just taken with the camera.

Claude Code wrote the code and read the production logs, I did the testing on the phone. Codex helped at the end.

First try, November 19

I noticed it right after a redesign of the upload dialog went live. Some photos failed with a network error, and retry gave the same error.

The server logs had nothing for the failed photos, not even a cut-off request. So the browser gave up before sending anything.

Claude’s guess was that the photos were only in the cloud, or were edited after being picked. It added a check that reads the first byte of the photo before uploading:

The problem is that catch. It throws away the error name, which was the only real clue.

November 22

It happened again, 1 of 7 photos failed. Claude went with the cloud theory again. I told it these were photos I had just taken with the camera, they were on the phone.

The next version logged the error name, NotReadableError. A web search found lots of GitHub projects with the same error and different explanations, and Claude suggested three fixes. They felt stupid, so I asked it to do more research.

It read some Chromium and Android source and found that Chrome refuses to read a file if its modification time (mtime) changed after it was picked. Then GitHub rate limited it, and it didn’t connect the dots.

Two things helped after that. I tried the same photos on the old site and all 5 worked, with the same photo picker. And I asked for diagnostic logging, only for my account, with a timeline for each photo. Since Claude had just seen that mtime check, it also logged how old each file claimed to be when it was picked. That ended up being the most useful thing in the logs.

Then came the guesses:

  • Chrome only refuses partial reads, so remove the 1-byte check. Two tests later, that was wrong too.
  • Copy every photo into memory right when it’s picked, then upload the copy. I tested it 3 times with 4 photos and it worked every time. Claude rolled it out for all Android users (it did suggest testing with more photos first). I tried 15 photos and 5 failed. It was rolled back after 16 minutes.

At that point I asked it to take a step back and review everything.

Testing four versions

Claude added an ?upload= parameter, only for my account, to switch between four versions of the uploader without deploying anything. I uploaded the same 15 photos every time:

What the page did with the picked photos Uploaded
no previews, nothing reads the photo before its upload 30/30
previews, upload from the picked file (what everyone had) 41/45
previews, photos copied one at a time 12/30
the old site, a few minutes earlier 15/15

The version without previews worked every time, so that’s what went live: no previews on Android. Each photo shows an empty square with a progress ring until it’s uploaded, then the thumbnail from the server. Another 15 of 15 on the live version. From my question to the fix it took about an hour.

Claude’s report said the reason was our page reading the photos. The fix was right, the reason wasn’t.

Codex

I gave the report to Codex and asked it to research it on its own. In its code review it had already found a problem with the fix: Android tablets in desktop mode report Linux instead of Android, so they would still get previews.

In about a minute and a half it found Chromium issue 586133901. It was filed a week earlier by an outside developer, reproduced on several devices, and it explained what I was seeing.

The actual cause

Chrome saves a file’s mtime when you pick it, and checks it again on every read. If it changed by 10 microseconds or more, the read is refused.

For photos from the Android photo picker, that mtime isn’t the photo’s real one:

  1. The picker gives Chrome a virtual file, served by Android’s MediaProvider through FUSE.
  2. MediaProvider sets that file’s mtime to the current time on every lookup.
  3. The Linux kernel doesn’t show the new mtime as long as it keeps the file’s inode in its cache.
  4. When the kernel drops the inode, for example under memory pressure, the next lookup creates it again, with a new mtime.
  5. That next lookup is Chrome’s own check at the start of a read. Chrome thinks the file changed, refuses the read, and the page gets NotReadableError with the message about permissions.

The photo itself never changes, the reporter checked the hashes. And the read that fails is the same one that creates the new mtime.

Chrome already has a workaround for this for files from the document chooser, with a comment about FUSE in the source. Photo picker files don’t get it.

Checking my own logs

The diagnostics were collected before I knew about the Chromium issue, so the next day I checked them against it. If the issue is right, the next time a photo is picked, its lastModified (the mtime as JavaScript sees it) should be the moment of its previous failed read.

All 10 failures I could check matched, within half a second.

For example, ten minutes after the 15-photo test with 5 failures, I picked the same 15 photos again (lines trimmed):

The 5 photos that had failed were “modified” 593 seconds before, the 10 that worked, 594.

It also explains why retry never worked. One photo failed at 14:26:26 and its retry at 14:26:43. The next time I picked it, its timestamp was 14:26:25.6. The first failed read set the new time, and the retry saw that new time, which doesn’t match what Chrome saved at the pick. So that File stays broken.

In the end

No previews on Android for now. It makes the problem rarer, but it can still happen if the kernel drops the inode before a photo’s turn. The retry button still shows and still can’t help, so a “pick again” button is planned. Previews come back when Chrome fixes it.

Why previews made it so much worse, I don’t know for sure. One explanation is memory: a 12 megapixel photo is about 50 MB decoded, so 15 previews at once is around 750 MB, and that could make Android drop those cached inodes. The old site works with one photo at a time. But I didn’t measure it, and some results don’t fit. It’s also just one phone, one afternoon, mostly the same 15 photos.

About the AIs. Like with PHP2Shell, Claude was very sure of itself and wrong a few times in one hour. But it also suggested most of the tests that found the answer: trying the old site, the diagnostics, the four versions. Codex found the issue very fast, but it started from a finished report with all the symptoms. I don’t know if that made the difference.

Leave a Reply

Your email address will not be published. Required fields are marked *