Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugin: Shut down gracefully on SIGINT #1201

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
### Improvements

- Plugin: clean up resources and exit cleanly on receiving SIGINT or CTRL_BREAK.

### Bug Fixes
10 changes: 8 additions & 2 deletions pkg/cmd/pulumi-language-java/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"io"
"os"
"os/exec"
"os/signal"
"strings"
"time"

Expand Down Expand Up @@ -97,13 +98,18 @@ func main() {
}

func setupHealthChecks(engineAddress string) (chan bool, error) {
// If we have a host cancel our cancellation context if it fails the healthcheck
ctx, cancel := context.WithCancel(context.Background())
// If the health check begins failing or we receive a SIGINT,
// we'll cancel the context.
//
// The returned channel is used to notify the server that it should
// stop serving and exit.
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)

// map the context Done channel to the rpcutil boolean cancel channel
cancelChannel := make(chan bool)
go func() {
<-ctx.Done()
cancel() // deregister the interrupt handler
close(cancelChannel)
}()
err := rpcutil.Healthcheck(ctx, engineAddress, 5*time.Minute, cancel)
Expand Down
Loading