-
Notifications
You must be signed in to change notification settings - Fork 141
Description
Server Version
0.4.0
Expected Behavior
On shutdown of the server (e.g. initiated by quitting the IDE) it should cancel any operations running on the root module, such as:
terraform version
- obtaining schema via
terraform providers schema -json
- parsing module manifest
Actual Behavior
Terraform executions will get cancelled either way, because they either inherit the session context or watcher context, both of which get cancelled as part of the shutdown:
terraform-ls/langserver/handlers/service.go
Lines 224 to 230 in c3bdf23
svc.logger.Println("Stopping watcher for session ...") | |
err := svc.ww.Stop() | |
if err != nil { | |
svc.logger.Println("Unable to stop watcher for session:", err) | |
} | |
svc.stopSession() |
A new challenge arises once we make walking asynchronous.
While the walker itself will be cancellable, the operations launched by the walker such as adding new root modules (and then performing any of the above) will retain context of the session and therefore can't be cancelled as part of walker cancellation.
This may result in multiple seconds of delay on shutdown while waiting for terraform to finish executing.
Further Context
Each root module gets its own non-cancellable context at the moment:
rm, err := rmm.newRootModule(context.Background(), dir) |
Generally the context-related logic in rootmodule
needs some overhaul to avoid persisting context.
This may require some more explicit workflow management, explicit cancellation of each individual RootModule
, and perhaps explicit cancellation of RootModuleManager
(which will in turn cancel and remove any tracked root modules).
In other words we should only be persisting context.CancelFunc
for each root module, but not the full context.