File tree 1 file changed +9
-2
lines changed
1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -86,10 +86,9 @@ func (eh *Handler) Handle(ctx context.Context, e caddyevents.Event) error {
86
86
expandedArgs [i ] = repl .ReplaceAll (eh .Args [i ], "" )
87
87
}
88
88
89
+ var cancel context.CancelFunc
89
90
if eh .Timeout > 0 {
90
- var cancel context.CancelFunc
91
91
ctx , cancel = context .WithTimeout (ctx , time .Duration (eh .Timeout ))
92
- defer cancel ()
93
92
}
94
93
95
94
cmd := exec .CommandContext (ctx , eh .Command , expandedArgs ... )
@@ -98,6 +97,10 @@ func (eh *Handler) Handle(ctx context.Context, e caddyevents.Event) error {
98
97
cmd .Stderr = os .Stderr
99
98
100
99
if eh .Foreground {
100
+ if cancel != nil {
101
+ defer cancel ()
102
+ }
103
+
101
104
err := cmd .Run ()
102
105
103
106
exitCode := cmd .ProcessState .ExitCode ()
@@ -111,10 +114,14 @@ func (eh *Handler) Handle(ctx context.Context, e caddyevents.Event) error {
111
114
}
112
115
113
116
go func () {
117
+ if cancel != nil {
118
+ defer cancel ()
119
+ }
114
120
if err := cmd .Run (); err != nil {
115
121
eh .logger .Error ("background command failed" , zap .Error (err ))
116
122
}
117
123
}()
124
+
118
125
return nil
119
126
}
120
127
You can’t perform that action at this time.
0 commit comments