Skip to content

Cancel root module operations on shutdown #195

@radeksimko

Description

@radeksimko

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:

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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions