Skip to content

Deadlock on Stop() #139

Open
Open
@zeroed-tech

Description

@zeroed-tech

Hi,
I've reciently started testing my Microsoft.Extensions.Hosting based console application outside Visual Studio and noticed when I kill the app using Ctrl+c, the shutdown process is getting blocked by client.Stop()

await client.StartOrFail();
outboxProcessor = OutboxProcessor(client, token);
await Task.WhenAll(outboxProcessor);
Logger.LogInformation("Closing socket");
await client.StopOrFail(WebSocketCloseStatus.NormalClosure, "Shutting down service");
Logger.LogInformation("Done");

I rebuilt my app using the Websocket-client source and stepped through it and it appears the lockup occurs when calling client.CloseAsync inside StopInternal() which as far as I can tell, is the boundrary between this library and .NET's own code.

I noticed that if I kill the connection from the server end, the DisconnectionHappened event fires with a type of DisconnectionType.ByUser (which can be seen in the below image).
image

Its like after I call stop, the client it trying to send a message but it getting blocked, and it only gives up when the other end kills the connection.

Any suggestions/recommendations?
Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions