Push notifications to api.push.apple.com sometimes fail

We have a case when we send 8 push notifications more or less simultaneously over 1 HTTP 2.0 connection. Using .NET Core 8

Sometimes some of them fail with a strange message: System.Net.Http.HttpRequestException: The response ended prematurely while waiting for the next frame from the server. (ResponseEnded) ---> System.Net.Http.HttpIOException: The response ended prematurely while waiting for the next frame from the server. (ResponseEnded) at System.Net.Http.Http2Connection.ThrowRequestAborted(Exception innerException) at System.Net.Http.Http2Connection.Http2Stream.TryEnsureHeaders() at System.Net.Http.Http2Connection.Http2Stream.ReadResponseHeadersAsync(CancellationToken cancellationToken) at System.Net.Http.Http2Connection.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) --- End of inner exception stack trace --- at System.Net.Http.Http2Connection.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken) at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.DecompressionHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at Microsoft.Extensions.Http.Logging.HttpClientLoggerHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)

We noticed that failure is always accompanied with a huge delay (~500ms) comparing to success (~20ms).

Also some of the burst messages are sent successfully (sometimes 2-4 of them)

What can we do about it?

Sending simultaneous push requests over a single connection means you are relying on HTTP/2 concurrent streams.

APNs allows multiple concurrent streams for each connection, and while the number of streams would usually be enough for 8 requests, don’t assume a specific number of streams.

The exact number varies based on server load and whether you use a provider certificate or an authentication token.

For example, when using an authentication token, APNs allows only one stream until you post a request with a valid authentication token.

So, I suggest you first make a single request until you receive the SETTINGS_MAX_CONCURRENT_STREAMS parameter from APNs, and then stay within that limit with your simultaneous requests.

Alternatively, you can use multiple connections.


Argun Tekant /  DTS Engineer / Core Technologies

If you believe the issue is with APNs not following the RFC properly, please feel free to file a bug.

Bug Reporting: How and Why? has tips on creating a successful bug report.

Push notifications to api.push.apple.com sometimes fail
 
 
Q