|
12 | 12 | using System.Text; |
13 | 13 | using System.Threading; |
14 | 14 | using System.Threading.Tasks; |
| 15 | +using Microsoft.Azure.WebJobs.Host; |
15 | 16 | using Microsoft.Azure.WebJobs.Script.Config; |
16 | 17 | using Microsoft.Azure.WebJobs.Script.Diagnostics; |
17 | 18 | using Microsoft.Azure.WebJobs.Script.Eventing; |
@@ -266,13 +267,15 @@ private bool ShutdownHostIfUnhealthy() |
266 | 267 | { |
267 | 268 | if (ShouldMonitorHostHealth && _healthCheckWindow.GetEvents().Where(isHealthy => !isHealthy).Count() > _config.HostHealthMonitor.HealthCheckThreshold) |
268 | 269 | { |
269 | | - // if the number of times the host has been unhealthy in |
| 270 | + // If the number of times the host has been unhealthy in |
270 | 271 | // the current time window exceeds the threshold, recover by |
271 | | - // initiating shutdown |
272 | | - var message = $"Host unhealthy count exceeds the threshold of {_config.HostHealthMonitor.HealthCheckThreshold} for time window {_config.HostHealthMonitor.HealthCheckWindow}. Initiating shutdown."; |
273 | | - Instance?.TraceWriter?.Error(message); |
| 272 | + // initiating a hard shutdown. |
| 273 | + var message = $"Host unhealthy count exceeds the threshold of {_config.HostHealthMonitor.HealthCheckThreshold} for time window {_config.HostHealthMonitor.HealthCheckWindow}. Initiating hard shutdown."; |
| 274 | + var shutdownEvent = new TraceEvent(TraceLevel.Error, message); |
| 275 | + shutdownEvent.Properties.Add(ScriptConstants.TracePropertyEventNameKey, ScriptConstants.ShutdownRecoveryEventName); |
| 276 | + Instance?.TraceWriter?.Trace(shutdownEvent); |
274 | 277 | Instance?.Logger?.LogError(0, message); |
275 | | - _environment.Shutdown(); |
| 278 | + _environment.Shutdown(hard: true); |
276 | 279 | return true; |
277 | 280 | } |
278 | 281 |
|
@@ -504,11 +507,11 @@ public virtual void RestartHost() |
504 | 507 | _restartHostEvent.Set(); |
505 | 508 | } |
506 | 509 |
|
507 | | - public virtual void Shutdown() |
| 510 | + public virtual void Shutdown(bool hard = false) |
508 | 511 | { |
509 | 512 | Stop(); |
510 | 513 |
|
511 | | - Process.GetCurrentProcess().Close(); |
| 514 | + Process.GetCurrentProcess().Kill(); |
512 | 515 | } |
513 | 516 |
|
514 | 517 | private void OnHostHealthCheckTimer(object state) |
|
0 commit comments