Simple-Http-Listener-PCL icon indicating copy to clipboard operation
Simple-Http-Listener-PCL copied to clipboard

Invalid Arguments exception

Open smyang10 opened this issue 3 years ago • 0 comments

I got this running in a Xamarin Android app, but after a few HTTP requests, eventually I will get an Invalid arguments exception. Below is the stack trace.

at System.Net.Sockets.SocketAsyncResult.CheckIfThrowDelayedException () [0x00014] in <7ccabb856481493484e46c69b5c3b288>:0 
  at System.Net.Sockets.Socket.EndAccept (System.Byte[]& buffer, System.Int32& bytesTransferred, System.IAsyncResult asyncResult) [0x0002c] in <7ccabb856481493484e46c69b5c3b288>:0 
  at System.Net.Sockets.Socket.EndAccept (System.IAsyncResult asyncResult) [0x00000] in <7ccabb856481493484e46c69b5c3b288>:0 
  at System.Net.Sockets.TcpListener.EndAcceptTcpClient (System.IAsyncResult asyncResult) [0x00026] in <7ccabb856481493484e46c69b5c3b288>:0 
  at System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func`2[T,TResult] endFunction, System.Action`1[T] endAction, System.Threading.Tasks.Task`1[TResult] promise, System.Boolean requiresSynchronization) [0x0000f] in <c72658f647bc485bbfb8c9fcaa790862>:0 

After that, the server becomes unresponsive and the app has to be restarted for it to work again. Sample code below:

      var observer = await listener.TcpHttpRequestObservable(port: Port, allowMultipleBindToSamePort: true);
      observer.Subscribe(
        async request =>
        {
          var response = new HttpResponse()
          {
            ResponseReason = HttpStatusCode.OK.ToString()
          };

          await listener.HttpSendReponseAsync(request, response).ConfigureAwait(false);

        },
        ex =>
        {
          // error is thrown here
        },
        () =>
        {
          
        });

smyang10 avatar Apr 15 '21 21:04 smyang10