Does a Notification Service Extension continue executing network requests after calling contentHandler?

In my Notification Service Extension I'm doing two things in parallel inside didReceive(_:withContentHandler:):

  1. Downloading and attaching a rich media image (the standard content modification work)
  2. Firing a separate analytics POST request (fire-and-forget I don't wait for its response)

Once the image is ready, I call contentHandler(modifiedContent). The notification renders correctly.

What I've observed (via Proxyman) is that the analytics POST request completes successfully after contentHandler has already been called.

My question: Why does this network request complete? Is it because:

(a) The extension process is guaranteed to stay alive for the full 30-second budget, even after contentHandler is called so my URLSession task continues executing during the remaining time?

(b) The extension process loses CPU time after contentHandler but remains in memory for process reuse and the request completes at the socket/OS level without my completion handler ever firing?

(c) Something else entirely?

I'd like to understand the documented behaviour so I can decide whether it's safe to rely on fire-and-forget network requests completing after contentHandler, or whether I need to ensure the request finishes before calling contentHandler.

It is a mixture of a number of things.

After calling contentHandler, the notification starts getting processed, and as far as you are concerned the NSE is done. If there is no memory pressure, and the extension is known to run frequently, the system may not terminate the process, but reuse it by leaving it in memory, and just give it execution time the next time it needs to run.

So, the process could stay alive after contentHandler, but it is not guaranteed. It could be terminated right after, or it could be left in memory for one notification, but could end up being terminated after another one.

The URLSession task continues to run, because the NSE process is not the one running it, but the system handles the network requests. The request may complete after calling contentHandler, but by the time it does there may be no process to return the results to.

So, it is not entirely safe to rely on this assumption, but you could fire-and-forget, as long as you can gracefully handle the situations where the process will not complete.

Waiting for the request to finish is risky. As on a slow network connection, you could miss the 30 second deadline, and then the NSE process would be terminated without the content being modified.

Does a Notification Service Extension continue executing network requests after calling contentHandler?
 
 
Q