镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Cancellation of Socket.ConnectAsync intermitently hangs #42198

Closed

Description

@ManickaP

When Socket.ConnectAsync is cancelled it might lead to a deadlock.

The cancellation code for MultipleConnectAsync tries to acquire a lock which is held by the connectAsync continuation (triggered by DoDnsCallback). The continuation then tries to dispose of the cancellation registration which will wait for all the callbacks if they've already been triggered.

This is easily reproducible with our HTTP stress suite (for HTTP 1.1 runs longer than 30 mins).

The biggest impact of this issue is that it prevents us from getting reasonable results from HTTP 1.1 stress pipeline on master. The pipeline gets cancelled on timeout and no results are available (AzDO empty logs).

Activity

  1. added this to the 6.0.0 milestone on Sep 14, 2020
  2. removed
    untriagedNew issue has not been triaged by the area owner
    on Sep 14, 2020
  3. changed the title [-]Socket.CancelAsync intermitently hangs[/-] [+]Socket.CancelConnectAsync intermitently hangs[/+] on Sep 14, 2020
  4. geoffkizer commented on Sep 14, 2020

    @geoffkizer
    Contributor

    In AttemptConnection, when ConnectAsync completes synchronously, we are calling InternalConnectCallback directly. This is bad since the caller of AttemptConnection should be holding the lock here.

    We should instead return to the caller and do the call to InternalConnectCallback outside the lock.

    Additionally, we should add asserts wherever we take the lock, but especially in the callbacks like InternalConnectCallback, that the lock is not already held by this thread -- basically, Debug.Assert(!Monitor.IsEntered(_lockObject)).

    And if a method is assuming the caller is holding the lock, like AttemptConnection is, we should add an assert that the lock is actually held. This is valuable not just to detect bugs, but also to document the expectation of the function.

  5. changed the title [-]Socket.CancelConnectAsync intermitently hangs[/-] [+]Cancelltion of Socket.ConnectAsync intermitently hangs[/+] on Sep 16, 2020
  6. changed the title [-]Cancelltion of Socket.ConnectAsync intermitently hangs[/-] [+]Cancellation of Socket.ConnectAsync intermitently hangs[/+] on Sep 16, 2020
  7. added a commit that references this issue on Sep 23, 2020
  8. riberk commented on Oct 19, 2020

    @riberk

    Is there a workaround? I have the same problem and i don`t know how to solve it from outside of the Socket class

  9. ManickaP commented on Nov 6, 2020

    @ManickaP
    MemberAuthor

    The only workaround is to avoid cancellation during socket connect. I don't know your exact problem so I cannot help much further at this point.

  10. ghost locked as resolved and limited conversation to collaborators on Dec 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions