fsprojects / FSharp.Data

F# Data: Library for Data Access
https://fsprojects.github.io/FSharp.Data
Other
806 stars 288 forks source link

When closing VS 2022, the FSharp.Data.DesignTime stays on lock that prevents closing the editor. #1466

Closed Thorium closed 7 months ago

Thorium commented 1 year ago

When closing VS 2022, the FSharp.Data.DesignTime stays on lock that prevents closing the editor. VS 2022 goes "busy" and unresponsive, and has to be killed via task manager.

Often when I try to close VS2022 it hangs. I attached another VS to VS, to see what is going on there, and it seems to be FSharp.Data.DesignTime that hangs everything.

It seems that there is a dead-lock, this lock locks the disposeActions here (on code line 2):

    let dispose typeNameOpt =
        lock disposeActions (fun () ->
            for i = disposeActions.Count - 1 downto 0 do
                let disposeAction = disposeActions.[i]
                let discard = disposeAction typeNameOpt
                if discard then disposeActions.RemoveAt(i))

typeNameOpt is null and there is 49 actions in the list. It calls setupDisposeAction and it seems the fileWatcher is the problem, as

    member __.Unsubscribe(name) =
        if subscriptions.Remove(name) then
            log (sprintf "Unsubscribed %s from %s watcher" name path)

            if subscriptions.Count = 0 then
                log (sprintf "Disposing %s watcher" path)
                watcher.Dispose()
                true
            else
                false
        else
            false

It tries to call watcher.Dispose() but that causes it to wait the locked disposeActions above.

image

Thorium commented 1 year ago

This seems to happen often in this scenario:

git branch A, file1.fs:
type MyType1 = FSharp.Data.JsonProvider<"my1.json", SampleIsList = true>

git branch B, file1.fs:
type MyType2 = FSharp.Data.JsonProvider<"my2.json", SampleIsList = true>

Now if I have VS open in branch A and then do git checkout B then VS tries to auto-reload the solution with new file content. If I now try to close the VS, it'll be busy forever.

I have both JSON and XML files, so I don't know which one or both are the guilty ones.