Skip to content

Commit

Permalink
Merge pull request #26 from uselagoon/handle-close
Browse files Browse the repository at this point in the history
fix: gracefully handle NATS connection close in ssh-portal
  • Loading branch information
smlx authored Mar 3, 2022
2 parents 68ae616 + 4a08784 commit e4df813
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cmd/ssh-portal/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ func (cmd *ServeCmd) Run(log *zap.Logger) error {
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGTERM)
defer stop()
// get nats server connection
nc, err := nats.Connect(cmd.NATSServer)
nc, err := nats.Connect(cmd.NATSServer,
// exit on connection close
nats.ClosedHandler(func(_ *nats.Conn) {
stop()
}))
if err != nil {
return fmt.Errorf("couldn't connect to NATS server: %v", err)
}
Expand Down

0 comments on commit e4df813

Please sign in to comment.