Skip to content

Commit

Permalink
🐛 Add cancel hook for file watcher
Browse files Browse the repository at this point in the history
Signed-off-by: Rintaro Okamura <[email protected]>
  • Loading branch information
rinx committed Jul 1, 2020
1 parent 543898b commit 1eac014
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion charts/vald/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1374,7 +1374,7 @@ agent:
auto_backup_duration: 10m
# @schema {"name": "agent.sidecar.config.post_stop_timeout", "type": "string"}
# agent.sidecar.config.post_stop_timeout -- timeout duration for file changing during post stop
post_stop_timeout: 10s
post_stop_timeout: 20s
# @schema {"name": "agent.sidecar.config.filename", "type": "string"}
# agent.sidecar.config.filename -- backup filename
filename: _MY_POD_NAME_
Expand Down
11 changes: 10 additions & 1 deletion pkg/agent/sidecar/service/observer/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,19 @@ func (o *observer) PostStop(ctx context.Context) (err error) {
return err
}

_, err = o.w.Start(ctx)
wctx, cancel := context.WithCancel(ctx)
defer cancel()

_, err = o.w.Start(wctx)
if err != nil {
return err
}
defer func() {
e := o.w.Stop(wctx)
if e != nil {
log.Error("an error occurred when watcher stopped:", e)
}
}()

for {
select {
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/sidecar/service/observer/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (
defaultOpts = []Option{
WithErrGroup(errgroup.Get()),
WithBackupDuration("10m"),
WithPostStopTimeout("10s"),
WithPostStopTimeout("20s"),
}
)

Expand Down

0 comments on commit 1eac014

Please sign in to comment.