I'm using PushSharp 4.0.10 to send iOS push notifications but I recently noticed that the console application hosting the broker to queue notifications to around 18,000 device tokens crashes after sending some notifications getting this error message:
[ERROR] APNS-CLIENT[1]: Send Batch Error: Batch ID=4, Err or=System.IO.IOException: Unable to write data to the transport connection: An e xisting connection was forcibly closed by the remote host. ---> System.Net.Socke ts.SocketException: An existing connection was forcibly closed by the remote hos t at System.Net.Sockets.Socket.EndSend(IAsyncResult asyncResult) at System.Net.Sockets.NetworkStream.EndWrite(IAsyncResult asyncResult)
--- End of inner exception stack trace --- at System.Net.Security._SslStream.EndWrite(IAsyncResult asyncResult)
at System.Net.Security.SslStream.EndWrite(IAsyncResult asyncResult)
at System.IO.Stream.<>c__DisplayClass0.b__17(Stream strea m, IAsyncResult asyncResult) at System.Threading.Tasks.TaskFactory1.FromAsyncTrimPromise
1.Complete(TInst ance thisRef, Func3 endMethod, IAsyncResult asyncResult, Boolean requiresSynchr onization) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot ification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
1.FromAsyncTrim[TInstance,TArgs](TInsta nce thisRef, TArgs args, Func
at PushSharp.Apple.ApnsConnection.<SendBatch>d__21.MoveNext() 2016-04-07 12:09:52.PM [ERROR] APNS-Client[1]: Reader Exception: System.IO.IOExc eption: Unable to read data from the transport connection: An established connec tion was aborted by the software in your host machine. ---> System.Net.Sockets.S ocketException: An established connection was aborted by the software in your ho st machine at System.Net.Sockets.Socket.BeginReceive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, AsyncCallback callback, Object state) at System.Net.Sockets.NetworkStream.BeginRead(Byte[] buffer, Int32 offset, In t32 size, AsyncCallback callback, Object state) --- End of inner exception stack trace --- at System.Net.Sockets.NetworkStream.BeginRead(Byte[] buffer, Int32 offset, In t32 size, AsyncCallback callback, Object state) at System.Net.FixedSizeReader.StartReading() at System.Net.Security._SslStream.StartFrameHeader(Byte[] buffer, Int32 offse t, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security._SslStream.StartReading(Byte[] buffer, Int32 offset, I nt32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security._SslStream.ProcessRead(Byte[] buffer, Int32 offset, In t32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security._SslStream.BeginRead(Byte[] buffer, Int32 offset, Int3 2 count, AsyncCallback asyncCallback, Object asyncState) at System.Net.Security.SslStream.BeginRead(Byte[] buffer, Int32 offset, Int32 count, AsyncCallback asyncCallback, Object asyncState) at System.IO.Stream.<>c__DisplayClass0.<BeginEndReadAsync>b__7(Stream stream, ReadWriteParameters args, AsyncCallback callback, Object state) at System.Threading.Tasks.TaskFactory5 beginMethod, Func
3 endMethod) at System.IO.Stream.BeginEndReadAsync(Byte[] buffer, Int32 offset, Int32 coun t) at System.IO.Stream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, Cance llationToken cancellationToken) at System.IO.Stream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count)
at PushSharp.Apple.ApnsConnection.d__23.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot ification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at PushSharp.Apple.ApnsConnection.d__21.MoveNext() 2016-04-07 12:09:59.PM [ERROR] APNS-CLIENT[1]: Send Batch Error: Batch ID=6, Err or=System.NullReferenceException: Object reference not set to an instance of an object. at PushSharp.Apple.ApnsConnection.createBatch(List`1 toSend) at PushSharp.Apple.ApnsConnection.d__21.MoveNext()Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object. at PushSharp.Apple.ApnsConnection.d__21.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot ification(Task task) at PushSharp.Apple.ApnsConnection.<<-ctor>b__1_0>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c__DisplayClass2. b__5(Object state) at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object sta te) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionCo ntext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, C ontextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWor kItem.ExecuteWorkItem() at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
Any idea why this happens? Is this related to concurrent connections? If yes, doesn't PushSharp handle this itself?