Skip to content

SignalR connection breaks when using window.print() in browser #63541

@cool-akash

Description

@cool-akash

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When calling window.print() from the client while connected to a SignalR hub, the SignalR connection closes unexpectedly.

It seems that window.print() freezes the browser UI thread, which prevents the client heartbeat/ping from being processed. As a result, SignalR considers the client unresponsive and closes the connection.

Environment:

  • ASP.NET Core (SignalR)
  • SignalR JavaScript client (browser)
  • Browser: Chrome/Edge (latest)

Expected Behavior

Expected Behavior:

  • The SignalR connection should remain stable during/after the print dialog is open.
  • Heartbeats should ideally tolerate temporary UI thread blocking.

Actual Behavior:

  • While the print dialog is open, no pings are sent.
  • After the ClientTimeoutInterval elapses, the connection closes with error:

Steps To Reproduce

Steps to Reproduce:

  1. Start a simple SignalR hub with default options:
    services.AddSignalR(options =>
    {
    options.EnableDetailedErrors = true;
    options.HandshakeTimeout = TimeSpan.FromSeconds(60);
    options.KeepAliveInterval = TimeSpan.FromSeconds(15);
    options.ClientTimeoutInterval = TimeSpan.FromSeconds(50);
    });

  2. Connect a JavaScript client in the browser.

  3. While connected, trigger a window.print() call.
    setTimeout(() => {
    window.print();
    }, 0);

4.Observe network traffic and logs.

Exceptions (if any)

Connection closed with an error.
OperationCanceledException: Client hasn't sent a message/ping within the configured ClientTimeoutInterval.

Log
"type":7,"error":"Connection closed with an error. OperationCanceledException: Client hasn't sent a message/ping within the configured ClientTimeoutInterval.","allowReconnect":true

.NET Version

8

Anything else?

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-signalrIncludes: SignalR clients and servers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions