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

fix: server failed to acknowledge more than 5 heartbeats - connection is zombie #10

Open
gretmn102 opened this issue May 15, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@gretmn102
Copy link
Owner

gretmn102 commented May 15, 2024

изображение

Last seen

The last time such an error was observed was in 2022. I may have accidentally fixed it at some point (see possible causes). Perhaps we should close the issue.

Reproduction

???

Possible causes {#posible-causes}

This can happen because of an exception in MailboxProccessor: when .PostAndReply is called, it waits for a response. If an exception occurs in MailboxProccessor before that, .PostAndReply will continue to wait indefinitely.

The following code can be used to prove this:

module AsyncLearning =
    open System.Threading.Tasks

    let awaiti (t: Task) =
        t.GetAwaiter().GetResult()

    type Msg =
        | Inc of AsyncReplyChannel<int>
        | GetCounter of AsyncReplyChannel<int>

    let reduce msg state =
        match msg with
        | Inc ->
            let counter = state + 1
            if counter > 1 then
                System.Threading.Tasks.Task.Run(fun x ->
                    failwithf "counter > 1"
                )
                |> awaiti

            counter

        | GetCounter r ->
            r.Reply state
            state

    let counter =
        let initState = 0

        MailboxProcessor.Start(fun mail ->
            let rec loop state =
                async {
                    let! msg = mail.Receive()
                    let state =
                        try
                            reduce msg state
                        with e ->
                            printfn "%A" e
                            state

                    return! loop state
                }
            loop initState
        )

    counter.PostAndReply (fun r -> Inc r)

    ()
@gretmn102 gretmn102 added the bug Something isn't working label May 15, 2024
@gretmn102 gretmn102 changed the title fix: zombie fix: server failed to acknowledge more than 5 heartbeats - connection is zombie May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: No status
Development

No branches or pull requests

1 participant