Skip to content

Commit 8268245

Browse files
committed
do not allow ScriptHost to be Initialized if we are handling errors on restart
1 parent 420fa46 commit 8268245

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/WebJobs.Script.WebHost/WebJobsScriptHostService.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ private async Task UnsynchronizedStartHostAsync(ScriptHostStartupOperation activ
227227
bool isOffline = Utility.CheckAppOffline(_environment, _applicationHostOptions.CurrentValue.ScriptPath);
228228
State = isOffline ? ScriptHostState.Offline : State;
229229
bool hasNonTransientErrors = startupMode.HasFlag(JobHostStartupMode.HandlingNonTransientError);
230+
bool handlingError = startupMode.HasFlag(JobHostStartupMode.HandlingError);
230231

231232
// If we're in a non-transient error state or offline, skip host initialization
232233
bool skipJobHostStartup = isOffline || hasNonTransientErrors;
@@ -244,7 +245,13 @@ private async Task UnsynchronizedStartHostAsync(ScriptHostStartupOperation activ
244245
if (scriptHost != null)
245246
{
246247
scriptHost.HostInitializing += OnHostInitializing;
247-
scriptHost.HostInitialized += OnHostInitialized;
248+
249+
if (!handlingError)
250+
{
251+
// Services may be initialized, but we don't want set the state to Initialized as we're
252+
// handling an error and want to retain the Error state.
253+
scriptHost.HostInitialized += OnHostInitialized;
254+
}
248255
}
249256

250257
LogInitialization(localHost, isOffline, attemptCount, ++_hostStartCount, activeOperation.Id);
@@ -266,7 +273,7 @@ private async Task UnsynchronizedStartHostAsync(ScriptHostStartupOperation activ
266273
await localHost.StartAsync(currentCancellationToken);
267274
}
268275

269-
if (!startupMode.HasFlag(JobHostStartupMode.HandlingError))
276+
if (!handlingError)
270277
{
271278
LastError = null;
272279

0 commit comments

Comments
 (0)