haskell / haskell-language-server

Official haskell ide support via language server (LSP). Successor of ghcide & haskell-ide-engine.
Apache License 2.0
2.61k stars 351 forks source link

Unify critical session running in hls #4256

Closed soulomoon closed 2 weeks ago

soulomoon commented 1 month ago

see #4251 What's done

  1. add Development.IDE.Core.Thread to provide common api to run a woker thread
  2. rewrite runWithDb using the Development.IDE.Core.Thread
  3. add session loading thread and session restart thread using Development.IDE.Core.Thread
  4. send session loading runs to session loading thread
  5. send session restart runs to session restart thread

The above modification ensure the shutdown handler can cancel the session loading and session restart. And hence we would have a more correct shutdown behaviour. Potentially make the test less likely to hang.

soulomoon commented 2 weeks ago

it's pretty much identical to having a resource that's guarded by a lock

yes, with a bit different, enqueued actions would not be cancelled even if the thread start it is cancelled.

It reminds me of something, we might probably want to limit some of the queue size to 1, so the waiting to enqueue action can be cancelled when we are doing shakeRestart. Then less likely a duplication actions would be run for the sessionLoadQueue But maybe in another PR, we might need to come up with some design, such as we might need a bit wrapping to do over TQueue and TMVar if we do it this way.