Skip to content

WebSocket error handling #4740

Closed
Closed

Description

@itg-assistant

Dino Novak asked 2025-03-26 20:32:10 UTC

I am experiencing strange web socket errors. is there a way to create a handler that would help me determine if this is caused by timeouts or something else ?

How wisej is handling "sessionTimeout" from Default.json, could this be connected to this web socket errors ?

Another question is how you can restart non managed app pool, sometimes if I try to do it from IIS console I am just getting Event Viewer log file failed to stop app pool.

This is

fail: Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer[2]
Connection ID "15348267531689264185", Request ID "8000043a-0000-d500-b63f-84710c7967bb": An unhandled exception was thrown by the application.
System.Net.WebSockets.WebSocketException (0x80004005): The remote party closed the WebSocket connection without completing the close handshake.
at System.Net.WebSockets.ManagedWebSocket.ThrowEOFUnexpected()
at System.Net.WebSockets.ManagedWebSocket.EnsureBufferContainsAsync(Int32 minimumRequiredBytes, CancellationToken cancellationToken)
at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder1.StateMachineBox1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
at System.Net.WebSockets.ManagedWebSocket.ReceiveAsyncPrivate[TResult](Memory1 payloadBuffer, CancellationToken cancellationToken) at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder1.StateMachineBox1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token) at System.Threading.Tasks.ValueTask1.ValueTaskSourceAsTask.<>c.<.cctor>b__4_0(Object state)
--- End of stack trace from previous location ---
at Wisej.Core.HttpHandler.ProcessWebSocketRequest(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1.ProcessRequestAsync()

Activity

  1. itg-assistant commented on Jun 16, 2026

    @itg-assistant
    Author

    Julie (ITG) answered 2025-03-27 13:08:58 UTC

    It's not an error to be handled and cannot be handled, it's already managed by the System.Net.WebSocket library which is not part of Wisej. It's a normal occurrence for the System.Net.WebSockets.ManagedWebSocket. You found it in the event viewer, not in the application. It's the websocket throwing an exception of a connection terminated for a variety of reasons.

    Julie

  2. added
    BugSomething is broken or behaving unexpectedly.
    on Jun 16, 2026
  3. itg-assistant commented on Jun 16, 2026

    @itg-assistant
    Author

    Dino Novak answered 2025-04-02 13:38:53 UTC

    Hi,
    this is a follow up error when Wisej App crashes due to error described here
    https://wisej.com/support/question/unknown-function-updatechildzorder-1

    Above mentioned error occurs, app crashes and then I get this as a followup error for all connected clients

    The only recovery is stop AppPool, restart of Web Service and AppPool restrat

  4. itg-assistant commented on Jun 16, 2026

    @itg-assistant
    Author

    Frank (ITG) answered 2025-04-02 14:19:31 UTC

    Hi Dino,

    in order to help you and investigate this we need a reproducible test case.

    Best regards
    Frank

  5. itg-assistant commented on Jun 16, 2026

    @itg-assistant
    Author

    Dino Novak answered 2025-04-02 16:26:14 UTC

    Hi
    unfortunately I am not successful in creating a test case where this would consistently pop us as problem,
    but let me share with you what is in place in order to try to catch this:

    1. We are restarting app pool daily before each workday in order to remove potential memory issues

    2. we do not see significant memory utilisation that could be linked to this error

    3. we are running app in non managed app pool with latest .net 8 and wisej binaries

    4. we tried running app with websockets enabled and disabled and in both cases this error pops up

    5. binary is configured in web.config to run with stdoutLogEnabled=”true” stdoutLogFile=”.\logs\stdout” hostingModel=”inprocess” and with

    6. In program.cs we have serology enabled with log to file and are defining thread handler
      Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);

    private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
    {
    // Log the exception or show a message to the user
    LogException(e.Exception);
    ShowErrorMessage(e.Exception);
    }

    1. in startup.cs we added
      app.UseExceptionHandler(
      options =>
      {
      options.Run(
      async context =>
      {

               context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
               context.Response.ContentType = &#8220;text/html&#8221;;
               var ex = context.Features.Get();
               if (ex != null)
               {
                   Log.Error($&#8221;Error: {ex.Error.Message} : {ex.Error.StackTrace}&#8221;);
                   var err = $&#8221;Error: {ex.Error.Message}{ex.Error.StackTrace}&#8221;;
                   await context.Response.WriteAsync(err).ConfigureAwait(false);
               }
           });
      

      }
      );

    And unfortunately we are unable to trace any appearance of this error.
    So any advice from your side would be more than welcomed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething is broken or behaving unexpectedly.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions