dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.47k stars 10.03k forks source link

SignalR ReactJS multiple connections #53163

Closed pankaj210891 closed 10 months ago

pankaj210891 commented 10 months ago

Is there an existing issue for this?

Describe the bug

I have implemented the @microsoft/signalr@8.0.0 also tried v7.0.12 and v6.0.33 in our project. It's a bidding website so realtime updates are essential part of the project.

Issue: Upto 3- 4 connections it works fine but when 5th connection is attempting to connect it stucks, and if we disconnect one of previous connected user then the 5th connection is connected.

What I have done: I checked the ReactJS and backend (ASP .net core ) code as it is as per the documentation. We have also increased the concurrent limit to 10k.

Below is the code used for connection to hub:

const getUpcomingLots = async () => { setLoading(true); try {

  let hubConnectionBuilder: any = new signalR.HubConnectionBuilder()
    .withUrl(HUBURL, {
      headers: {
        "Cross-Origin-Resource-Policy": "*",
      },
      withCredentials: false,
    })
    .withAutomaticReconnect()
    .build();

  hubConnectionBuilder.start().then(() => {
    hubConnectionBuilder.on("SendUpcomingLots", (data: any) => {
      setUpcomingLots(data);
    });

    axios
      .get(`${APIURL}?auctionId=${ID}&customerId=${customerId}`)
      .then(() => {
        setLoading(false);
      })
      .catch(() => {
        console.log("APIURL Error Send", new Date());
      });
  });

} catch (error) {
  setLoading(false);
  console.error(error);
}

};

LiveAuction.txt

Note: If anything else is required, please drop a comment here.

Any help is appreciated.

Expected Behavior

Multiple connections should work. Even if 1000 users connects to the hub they all should receive the realtime updates.

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

7.0

Anything else?

No response

pankaj210891 commented 10 months ago

We have resolved this issue. Just mentioning the solution here for future developers.

Issue was from backend as our code was deployed on IIS server on Windows 10 which has limit of 10 concurrent connections. We moved the hosting to OS Server as it supports unlimited concurrent connections and Voila issue was resolved.

Now we can connect as many users as we want.