@@ -235,42 +235,42 @@ func (t *Telegraf) watchLocalConfig(ctx context.Context, signals chan os.Signal,
235
235
236
236
// Setup debounce timer
237
237
var reloadTimer * time.Timer
238
- var reloadPending bool
239
-
240
- if t .watchDebounceInterval > 0 {
241
- reloadTimer = time .NewTimer (t .watchDebounceInterval )
242
- if ! reloadTimer .Stop () {
243
- <- reloadTimer .C // Drain if already fired
244
- }
245
- }
246
-
247
- // Update resetTimer function:
248
- resetTimer := func (reason string ) {
249
- log .Printf ("%s" , reason )
250
-
251
- if t .watchDebounceInterval == 0 {
252
- // No debouncing - trigger immediately
253
- select {
254
- case signals <- syscall .SIGHUP :
255
- case <- ctx .Done ():
256
- return
257
- }
258
- return
259
- }
260
-
261
- if ! reloadPending {
262
- reloadPending = true
263
- }
264
-
265
- // Properly drain and reset timer
266
- if ! reloadTimer .Stop () {
267
- select {
268
- case <- reloadTimer .C :
269
- default :
270
- }
271
- }
272
- reloadTimer .Reset (t .watchDebounceInterval )
273
- }
238
+ var reloadPending bool
239
+
240
+ if t .watchDebounceInterval > 0 {
241
+ reloadTimer = time .NewTimer (t .watchDebounceInterval )
242
+ if ! reloadTimer .Stop () {
243
+ <- reloadTimer .C // Drain if already fired
244
+ }
245
+ }
246
+
247
+ // Update resetTimer function:
248
+ resetTimer := func (reason string ) {
249
+ log .Printf ("%s" , reason )
250
+
251
+ if t .watchDebounceInterval == 0 {
252
+ // No debouncing - trigger immediately
253
+ select {
254
+ case signals <- syscall .SIGHUP :
255
+ case <- ctx .Done ():
256
+ return
257
+ }
258
+ return
259
+ }
260
+
261
+ if ! reloadPending {
262
+ reloadPending = true
263
+ }
264
+
265
+ // Properly drain and reset timer
266
+ if ! reloadTimer .Stop () {
267
+ select {
268
+ case <- reloadTimer .C :
269
+ default :
270
+ }
271
+ }
272
+ reloadTimer .Reset (t .watchDebounceInterval )
273
+ }
274
274
275
275
for {
276
276
select {
@@ -282,47 +282,47 @@ func (t *Telegraf) watchLocalConfig(ctx context.Context, signals chan os.Signal,
282
282
case <- changes .Modified :
283
283
resetTimer (fmt .Sprintf ("I! Config file/directory %q modified\n " , fConfig ))
284
284
285
- case <- changes .Deleted :
286
- // Use select with timeout instead of blocking wait
287
- timer := time .NewTimer (time .Second )
288
- select {
289
- case <- timer .C :
290
- // Proceed with file existence check
291
- case <- ctx .Done ():
292
- timer .Stop ()
293
- return
294
- }
295
-
296
- var reason string
297
- if _ , err := os .Stat (fConfig ); err == nil {
298
- reason = fmt .Sprintf ("I! Config file/directory %q overwritten\n " , fConfig )
299
- } else {
300
- reason = fmt .Sprintf ("W! Config file/directory %q deleted\n " , fConfig )
301
- }
302
- resetTimer (reason )
285
+ case <- changes .Deleted :
286
+ // Use select with timeout instead of blocking wait
287
+ timer := time .NewTimer (time .Second )
288
+ select {
289
+ case <- timer .C :
290
+ // Proceed with file existence check
291
+ case <- ctx .Done ():
292
+ timer .Stop ()
293
+ return
294
+ }
295
+
296
+ var reason string
297
+ if _ , err := os .Stat (fConfig ); err == nil {
298
+ reason = fmt .Sprintf ("I! Config file/directory %q overwritten\n " , fConfig )
299
+ } else {
300
+ reason = fmt .Sprintf ("W! Config file/directory %q deleted\n " , fConfig )
301
+ }
302
+ resetTimer (reason )
303
303
304
304
case <- changes .Truncated :
305
305
resetTimer (fmt .Sprintf ("I! Config file/directory %q truncated\n " , fConfig ))
306
306
307
307
case <- changes .Created :
308
308
resetTimer (fmt .Sprintf ("I! Config directory %q has new file(s)\n " , fConfig ))
309
309
310
- case <- func () <- chan time.Time {
311
- if reloadTimer != nil {
312
- return reloadTimer .C
313
- }
314
- // Return a channel that never fires when debouncing is disabled
315
- return make (<- chan time.Time )
316
- }():
317
- if reloadPending {
318
- log .Printf ("I! Debounce period elapsed, triggering config reload for %q\n " , fConfig )
319
- select {
320
- case signals <- syscall .SIGHUP :
321
- case <- ctx .Done ():
322
- return
323
- }
324
- reloadPending = false
325
- }
310
+ case <- func () <- chan time.Time {
311
+ if reloadTimer != nil {
312
+ return reloadTimer .C
313
+ }
314
+ // Return a channel that never fires when debouncing is disabled
315
+ return make (<- chan time.Time )
316
+ }():
317
+ if reloadPending {
318
+ log .Printf ("I! Debounce period elapsed, triggering config reload for %q\n " , fConfig )
319
+ select {
320
+ case signals <- syscall .SIGHUP :
321
+ case <- ctx .Done ():
322
+ return
323
+ }
324
+ reloadPending = false
325
+ }
326
326
327
327
case <- mytomb .Dying ():
328
328
reloadTimer .Stop ()
0 commit comments