Skip to content

Commit

Permalink
More threadpool exhaustion fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAngryByrd committed Mar 15, 2023
1 parent a80fdd5 commit c66df2e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
22 changes: 13 additions & 9 deletions src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ type AdaptiveFSharpLspServer(workspaceLoader: IWorkspaceLoader, lspClient: FShar

()
}
|> Async.RunSynchronouslyWithCT ct
|> fun work -> Async.StartImmediate(work, ct)
with :? OperationCanceledException as e ->
()

Expand Down Expand Up @@ -717,7 +717,7 @@ type AdaptiveFSharpLspServer(workspaceLoader: IWorkspaceLoader, lspClient: FShar
use progressReport = new ServerProgressReport(lspClient)

progressReport.Begin($"Loading {projects.Count} Projects")
|> Async.RunSynchronously
|> Async.StartImmediate

let projectOptions =
loader.LoadProjects(projects |> Seq.map (fst >> UMX.untag) |> Seq.toList, [], binlogConfig)
Expand Down Expand Up @@ -1015,8 +1015,18 @@ type AdaptiveFSharpLspServer(workspaceLoader: IWorkspaceLoader, lspClient: FShar


do
let filesystemShim file =
// GetLastWriteTimeShim gets called _alot_ and when we do checks on save we use Async.Parallel for type checking.
// Adaptive uses lots of locks under the covers, so many threads can get blocked waiting for data.
// We know we don't store anything other than Fsharp type files in open files so this so we shouldn't hit any locks
// when F# compiler asks for DLL timestamps
if Utils.isFileWithFSharp %file then
forceFindOpenFile file
else
None

FSharp.Compiler.IO.FileSystemAutoOpens.FileSystem <-
FileSystem(FSharp.Compiler.IO.FileSystemAutoOpens.FileSystem, forceFindOpenFile)
FileSystem(FSharp.Compiler.IO.FileSystemAutoOpens.FileSystem, filesystemShim)

let forceFindSourceText filePath =
forceFindOpenFileOrRead filePath |> Result.map (fun f -> f.Lines)
Expand Down Expand Up @@ -1181,11 +1191,6 @@ type AdaptiveFSharpLspServer(workspaceLoader: IWorkspaceLoader, lspClient: FShar
let simpleName = Path.GetFileName(UMX.untag file.Lines.FileName)
do! progressReport.Begin($"Typechecking {simpleName}", message = $"{file.Lines.FileName}")


// HACK: Insurance for a bug where FCS invalidates graph nodes incorrectly and seems to typecheck forever
use cts = new CancellationTokenSource()
cts.CancelAfter(TimeSpan.FromSeconds(60.))

let! result =
checker.ParseAndCheckFileInProject(
file.Lines.FileName,
Expand All @@ -1194,7 +1199,6 @@ type AdaptiveFSharpLspServer(workspaceLoader: IWorkspaceLoader, lspClient: FShar
options,
shouldCache = shouldCache
)
|> Async.withCancellation cts.Token
|> Debug.measureAsync $"checker.ParseAndCheckFileInProject - {file.Lines.FileName}"

do! progressReport.End($"Typechecked {file.Lines.FileName}")
Expand Down
4 changes: 2 additions & 2 deletions src/FsAutoComplete/LspServers/FSharpLspClient.fs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ type ServerProgressReport(lspClient: FSharpLspClient, ?token: ProgressToken) =

interface IDisposable with
member x.Dispose() =
(x :> IAsyncDisposable).DisposeAsync().GetAwaiter().GetResult()
(x :> IAsyncDisposable).DisposeAsync() |> ignore


open System.Diagnostics.Tracing
Expand Down Expand Up @@ -279,7 +279,7 @@ type ProgressListener(lspClient: FSharpLspClient, traceNamespace: string array)

interface IDisposable with
member this.Dispose() : unit =
(this :> IAsyncDisposable).DisposeAsync().GetAwaiter().GetResult()
(this :> IAsyncDisposable).DisposeAsync() |> ignore

interface IAsyncDisposable with
member this.DisposeAsync() : ValueTask =
Expand Down

0 comments on commit c66df2e

Please sign in to comment.