handleWatchedConfigChange is invoked by the watcher on a debounced fire. It triggers a singleflight Reload using the most recently observed path set so the cached server map and snapshot are refreshed without waiting for the next HTTP request.
()
| 355 | // snapshot are refreshed without waiting for the next HTTP |
| 356 | // request. |
| 357 | func (m *Manager) handleWatchedConfigChange() { |
| 358 | m.mu.RLock() |
| 359 | paths := slices.Clone(m.lastPaths) |
| 360 | closed := m.closed |
| 361 | m.mu.RUnlock() |
| 362 | if closed || len(paths) == 0 { |
| 363 | return |
| 364 | } |
| 365 | |
| 366 | logger := m.logger.With(slog.F("trigger", "fsnotify")) |
| 367 | logger.Debug(m.ctx, "reloading due to config change") |
| 368 | if err := m.Reload(m.ctx, paths); err != nil { |
| 369 | if errors.Is(err, ErrManagerClosed) || |
| 370 | errors.Is(err, context.Canceled) { |
| 371 | logger.Debug(m.ctx, |
| 372 | "watched reload short-circuited by shutdown", |
| 373 | slog.Error(err)) |
| 374 | return |
| 375 | } |
| 376 | logger.Warn(m.ctx, "watched reload failed", slog.Error(err)) |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | func (m *Manager) waitReload(ctx context.Context, ch <-chan reloadResult, timeout time.Duration) error { |
| 381 | // Prefer caller cancellation when it already happened before the |