Skip to content

System.InvalidOperationException: Renci.SshNet.Abstractions.SocketExtensions+_ConnectAsync_d__1.MoveNext #913

Closed
@paulmaybee

Description

@paulmaybee

We are seeing crashes when an async connect operation is canceled. Analyses of the crash leads me to believe that SocketAsyncEventArgsAwaitable.SetCompleted is being called twice: once during the handling of the cancel and once when the IOCompletion fires. However the code that runs the continuationAction does not handle this condition appropriately and runs the continuationAction twice, causing the InvalidOperationException. Changing this line in SetCompleted:

var continuation = continuationAction ?? Interlocked.CompareExchange(ref continuationAction, SENTINEL, null);

to:

var continuation = Interlocked.Exchange(ref continuationAction, SENTINEL);

seems to fix the problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions