From 0b5a36c876fea19036269e156448a336f1428442 Mon Sep 17 00:00:00 2001 From: Sergio Salvatore Date: Thu, 29 Aug 2024 14:23:03 -0400 Subject: [PATCH] Fix Source Error Hang This fixes a bug in ez where an error thrown by a Source may cause the process to hang. --- ez/ez.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ez/ez.go b/ez/ez.go index cbd77be..d32e9b6 100644 --- a/ez/ez.go +++ b/ez/ez.go @@ -171,16 +171,6 @@ func ConfigFileEnvFlagDecoderFactoryParams[T any, TP ConfigWithConfigPath[T]](ct flagSrc = fset } - // If file-watching is not enabled, we should shutdown the monitor - // goroutine when exiting this function. - // Usually `dials.Config` is smart enough not to start a monitor when - // there are no `Watcher` implementations in the source-list, but the - // `Blank` source uses `Watcher` for its core functionality, so we need - // to shutdown the blank source to actually clean up resources. - if !params.WatchConfigFile { - defer blank.Done(ctx) - } - dp := dials.Params[T]{ // Set the OnNewConfig callback. It'll be suppressed by the // CallGlobalCallbacksAfterVerificationEnabled until just before we return. @@ -199,6 +189,16 @@ func ConfigFileEnvFlagDecoderFactoryParams[T any, TP ConfigWithConfigPath[T]](ct return nil, err } + // If file-watching is not enabled, we should shutdown the monitor + // goroutine when exiting this function. + // Usually `dials.Config` is smart enough not to start a monitor when + // there are no `Watcher` implementations in the source-list, but the + // `Blank` source uses `Watcher` for its core functionality, so we need + // to shutdown the blank source to actually clean up resources. + if !params.WatchConfigFile { + defer blank.Done(ctx) + } + basecfg := d.View() cfgPath, filepathSet := (TP)(basecfg).ConfigPath() if !filepathSet {