Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception on browser close #3358

Closed
ArjunPathak opened this issue Dec 5, 2014 · 9 comments
Closed

Exception on browser close #3358

ArjunPathak opened this issue Dec 5, 2014 · 9 comments

Comments

@ArjunPathak
Copy link

Hey guys, as I have already found one sibling who was facing same issue and i posted there.
(#2804)
Since it was closed thread I am putting it here to bring it to the notice and could get more information. Here are the details.

We have setup SignalR (2.1.1) server and client in 2 different virtual directories on IIS. We are hosting them on Amazon servers that also configured with ELB (load balancing)

Our requirement is : When user close or refresh the browser/tab then we need to make a hub call to notify server and back to back 2nd call to stop its current hub. ie. this line : $.connection.hub.stop();
We have keep both calls as follows:

window.onbeforeunload = function (e) {
if (!isCloseAppInvoked) { InvokeCloseApp(); }
return undefined; //To avoid native js message that asks "Are you sure you want to leave this page" };

function onBeforeUnload_Success(response) { $.connection.hub.stop(); }
function onBeforeUnload_Error(response) { }

Now, the scenario is- Referring the same closed post - If we remove window.onbeforeunload from respective pages, we don't see any instance of exception. We have confirmed this in many test cycles. Also we see these in chrome and firefox also regardless IE.
And as we re-enable this, we get following exceptions.

Global.asax.cs:: Application_Error() :: System.Web.HttpException
The client disconnected.
at System.Web.Hosting.IIS7WorkerRequest.EndRead(IAsyncResult asyncResult)
at System.Web.HttpBufferlessInputStream.EndRead(IAsyncResult asyncResult)
at System.IO.Stream.b__e(Stream stream, IAsyncResult asyncResult)
at System.Threading.Tasks.TaskFactory1.FromAsyncTrimPromise1.Complete(TInstance thisRef, Func`3 endMethod, IAsyncResult asyncResult, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.IO.StreamReader.d__28.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.HandleNonSuccessAndDebuggerNotification(Task task)
at System.IO.StreamReader.d__19.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.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Owin.OwinRequest.d__0.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.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.SignalR.Owin.ServerRequest.d__3.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.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.SignalR.Transports.LongPollingTransport.d__12.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.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Owin.Mapping.MapMiddleware.d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar)
at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar)
at System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
/beastappscore/signalr/send?transport=longPolling&clientProtocol=1.4&connectionToken=tB9RjeQKi3ZQVa%2FaoJQeWvYoAykSJGi4vWvWAm5VRBGQjYp5bj4IEI2je%2FVqDzMJpnuTI614AGnVAyJz1HOrEZARVK0vuhpPkama%2B6Ebq9DuOSAgZI8gV3ZU2UECkvKI&connectionData=%5B%7B%22name%22%3A%22marketdatahub%22%7D%5D

IIS side event viewer shows
Event Id = 1309 and
Eventcode = 3005 (for signalr server virtual directory)
Eventcode = 3012 (for signalr client virtual directory)

Please let us know your thoughts. We are more happy to give you further configuration details whatever you want.

Thanks in advance..

@ArjunPathak
Copy link
Author

Has anyone got any fix or workaround for this ?

@aspnet-hello
Copy link

This issue has been closed as part of issue clean-up as described in https://blogs.msdn.microsoft.com/webdev/2018/09/17/the-future-of-asp-net-signalr/. If you're still encountering this problem, please feel free to re-open and comment to let us know! We're still interested in hearing from you, the backlog just got a little big and we had to do a bulk clean up to get back on top of things. Thanks for your continued feedback!

@jzabroski
Copy link

Last I recall, this issue was a wont fix and by design. THIS ISSUE is why I don't use SignalR.

@analogrelay
Copy link
Contributor

Unfortunately this issue is beyond SignalR's control since it is coming from the ASP.NET hosting infrastructure. The underlying TCP connection is being closed by the browser while SignalR is in the middle of invoking a method so the exception occurs. Browsers don't provide us a way to guarantee the connection stays open (they don't want JavaScript to be able to hold on to resources after the page is unloaded) so the browser forcibly closes the connection and triggers this exception on the server.

@jzabroski
Copy link

jzabroski commented Sep 21, 2018 via email

@analogrelay
Copy link
Contributor

You're welcome to not host your app on ASP.NET, SignalR supports Owin self-host just fine.

@jzabroski
Copy link

jzabroski commented Sep 21, 2018 via email

@analogrelay
Copy link
Contributor

It would depend on the host's behavior when the underlying TCP connection is terminated. SignalR doesn't have any control over that behavior. What's the goal you're trying to achieve here? Just suppressing the exception?

@analogrelay
Copy link
Contributor

To be clear, SignalR isn't really in control of the events that trigger this exception. Calling .stop in an onbeforeunload handler is an inherant race between the stop request completing and the browser unloading the page. We can't stop the browser from continuing to unload the page, and if the stop request doesn't get all the way through before the browser unloads the page (and terminates the TCP connection) then most hosts will raise some kind of error for that request since the TCP connection was terminated out from under it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants