Skip to content

Commit 4196382

Browse files
committed
Fix goroutine leak
1 parent 9b5d6e3 commit 4196382

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

pkg/sshgate/sshgate.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,6 @@ func notifyConfigReload(ctx context.Context, config *Config) (context.Context, e
233233
if err != nil {
234234
return nil, err
235235
}
236-
go func() {
237-
<-ctx.Done()
238-
watcher.Close()
239-
}()
240236

241237
if err := watcher.Add(config.path); err != nil {
242238
return nil, err
@@ -254,7 +250,14 @@ func notifyConfigReload(ctx context.Context, config *Config) (context.Context, e
254250
}
255251
}
256252

257-
return fsnotifyContext(ctx, watcher), nil
253+
ctx = fsnotifyContext(ctx, watcher)
254+
255+
go func() {
256+
<-ctx.Done()
257+
watcher.Close()
258+
}()
259+
260+
return ctx, nil
258261
}
259262

260263
func fsnotifyContext(ctx context.Context, watcher *fsnotify.Watcher) context.Context {

0 commit comments

Comments
 (0)