Skip to content

[SDK-871] Retry the push notification image once on API 31+ when the download fails - #1110

Merged
franco-zalamena-iterable merged 2 commits into
masterfrom
fix/SDK-871-push-image-retry
Nov 24, 2026
Merged

franco-zalamena-iterable merged 2 commits into
masterfrom
fix/SDK-871-push-image-retry

Conversation

@franco-zalamena-iterable

@franco-zalamena-iterable franco-zalamena-iterable commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

📝 Summary

On API 31+, if the push image fails to download, the SDK retries it once when there is network and adds it to the notification already showing. Every image download also gives up after 15s now, so a stalled download doesn't hold the notification back

🎟️ Jira Ticket: SDK-871

📖 Description

Thanks @konrad-journi for the report and for proposing the first fix

Our backend never sets an FCM priority, so Android pushes arrive as normal priority. When the app is in the rare or restricted standby bucket, in Doze or in battery saver, its network is blocked while the image worker runs, so the download fails with UnknownHostException and the notification shows text only. Data Saver on a metered network blocks it at any priority

The proposed one liner adds a CONNECTED constraint to the first request. We didn't take it as is because it holds the notification itself until the constraint is met, which under Data Saver can be indefinitely. It also only helps on API 31+, where expedited jobs with a network constraint get past the standby network block, and it broke an existing test

This PR keeps the first request unconstrained, the notification still posts right away and is text only if the image fails. On API 31+, if the download fails with an IOException and the push has a messageId, we enqueue one follow up job. It is unique per notification, expedited and has a CONNECTED constraint

The follow up waits until at least 3s have passed since the first failure, because Android caches a failed DNS lookup for 2s. Then it downloads the image with 15s timeouts and re-posts the same notification with the image. It uses setOnlyAlertOnce and the original when, so there is no second alert and the notification doesn't jump to the top

It does nothing if the notification was dismissed, belongs to a different push, is older than 24h, the worker was stopped or the image fails again. There is no retry loop

The first image download had no timeout, so a stalled connection held back the notification itself. On an emulator it once hung for 134s. Every image download now gives up after 15s without connecting or without receiving data. That covers the first attempt, the follow up and apps that build notifications themselves through IterableNotificationHelper.createNotification

The image is still decoded as it streams, but a read error the decoder would swallow, including a timeout, now counts as a failed download. So a stall partway through the image posts the notification text only and on API 31+ the follow up adds the image, instead of a cut off image being posted. A stall only in the bytes after a complete image still shows the image. An image that downloads but can't be decoded still posts text only, with no retry. Below API 31 the timeout applies too, there is just no follow up

Known gaps: the notification's timestamp is set before the image download starts, so after a stalled download it reads up to about 15s earlier than when the notification appeared. This is already the case on master and it's only cosmetic

🧪 How to test?

Unit tests cover:

  • the first request stays unconstrained
  • a follow up is scheduled on API 31 and 34, but not on 30
  • no follow up when the image loads or the push has no messageId
  • the re-post keeps the same id, alert once and the original when
  • nothing is posted when the notification was dismissed (also during the download), is a different push or is older than 24h
  • the retry delay
  • an end to end flow where the first download gets a 503 and the retry posts the image
  • the 15s default timeout, and that it is applied to both connect and read
  • a server that never responds posts text only after the timeout, with a follow up on API 31 and 34 but not on 30
  • a stall partway through the body posts text only with no cut off image, with a follow up on API 34 but not on 30
  • an image that can't be decoded posts text only with no retry
  • a complete image followed by a stall on extra bytes still shows the image, with no retry

Manual tests on a Medium Phone emulator, API 36, with real FCM pushes at normal priority unless noted:

  • on master, rare, restricted, Doze and battery saver all show text only
  • with the fix, rare (twice), restricted and battery saver show text only right away, and the image is added to the same notification about 3.3s later with no second sound
  • under Data Saver on a metered network (high priority push) the notification shows right away and the image is added once Data Saver is lifted
  • a notification dismissed before the follow up, or during its wait, doesn't come back
  • the active bucket control (high priority) and text only pushes are unchanged

With the timeout, on the same emulator:

  • a server that never responds shows text only after about 15.8s, and an address that never connects after about 15.4s
  • a stall partway through the image shows text only after about 15.5s, then the image is added to the same notification about 3.2s later with no second sound
  • a complete image followed by a stall on extra bytes shows the image on the first post, with no follow up
  • garbage image bytes show text only with no follow up
  • the rare bucket case and the active bucket control are unchanged

🧾 Changelog

Added under Unreleased

🐞 Github Issues solved

Issue: #1109

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@franco-zalamena-iterable
franco-zalamena-iterable requested a review from a team as a code owner November 18, 2026 12:50
@jena-chakour
jena-chakour self-requested a review November 20, 2026 21:44

@jena-chakour jena-chakour left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@franco-zalamena-iterable would it be good to add a timeout for the first attempt? otherwise fwiw LGTM

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@franco-zalamena-iterable

Copy link
Copy Markdown
Contributor Author

@franco-zalamena-iterable would it be good to add a timeout for the first attempt? otherwise fwiw LGTM

Last commit added it, i was leaving it out to a separate ticket to try to make this one more concise but i think we can add it in this same PR maybe makes it more clear

@joaodordio joaodordio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@konrad-journi konrad-journi left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this branch and can confirm the fix works

@franco-zalamena-iterable
franco-zalamena-iterable merged commit c83a089 into master Nov 24, 2026
10 checks passed
@franco-zalamena-iterable
franco-zalamena-iterable deleted the fix/SDK-871-push-image-retry branch November 24, 2026 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Push notification image not displayed when app is rarely used

4 participants