Skip to content

Commit aedab0b

Browse files
committed
preventing races during specialization
1 parent 1110a9d commit aedab0b

File tree

8 files changed

+397
-210
lines changed

8 files changed

+397
-210
lines changed

src/WebJobs.Script.WebHost/Diagnostics/Extensions/ScriptHostServiceLoggerExtension.cs

Lines changed: 87 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -12,115 +12,127 @@ public static class ScriptHostServiceLoggerExtension
1212

1313
private static readonly Action<ILogger, Exception> _scriptHostServiceInitCanceledByRuntime =
1414
LoggerMessage.Define(
15-
LogLevel.Information,
16-
new EventId(500, nameof(ScriptHostServiceInitCanceledByRuntime)),
17-
"Initialization cancellation requested by runtime.");
15+
LogLevel.Information,
16+
new EventId(500, nameof(ScriptHostServiceInitCanceledByRuntime)),
17+
"Initialization cancellation requested by runtime.");
1818

1919
private static readonly Action<ILogger, int, TimeSpan, Exception> _unehealthyCountExceeded =
2020
LoggerMessage.Define<int, TimeSpan>(
21-
LogLevel.Error,
22-
new EventId(501, nameof(UnhealthyCountExceeded)),
23-
"Host unhealthy count exceeds the threshold of {healthCheckThreshold} for time window {healthCheckWindow}. Initiating shutdown.");
21+
LogLevel.Error,
22+
new EventId(501, nameof(UnhealthyCountExceeded)),
23+
"Host unhealthy count exceeds the threshold of {healthCheckThreshold} for time window {healthCheckWindow}. Initiating shutdown.");
2424

2525
private static readonly Action<ILogger, Exception> _offline =
2626
LoggerMessage.Define(
27-
LogLevel.Information,
28-
new EventId(502, nameof(Offline)),
29-
"Host is offline.");
27+
LogLevel.Information,
28+
new EventId(502, nameof(Offline)),
29+
"Host is offline.");
3030

3131
private static readonly Action<ILogger, Exception> _initializing =
3232
LoggerMessage.Define(
33-
LogLevel.Information,
34-
new EventId(503, nameof(Initializing)),
35-
"Initializing Host.");
33+
LogLevel.Information,
34+
new EventId(503, nameof(Initializing)),
35+
"Initializing Host.");
3636

3737
private static readonly Action<ILogger, int, int, Exception> _initialization =
3838
LoggerMessage.Define<int, int>(
39-
LogLevel.Information,
40-
new EventId(504, nameof(Initialization)),
41-
"Host initialization: ConsecutiveErrors={attemptCount}, StartupCount={startCount}");
39+
LogLevel.Information,
40+
new EventId(504, nameof(Initialization)),
41+
"Host initialization: ConsecutiveErrors={attemptCount}, StartupCount={startCount}");
4242

4343
private static readonly Action<ILogger, Exception> _inStandByMode =
4444
LoggerMessage.Define(
45-
LogLevel.Information,
46-
new EventId(505, nameof(InStandByMode)),
47-
"Host is in standby mode");
45+
LogLevel.Information,
46+
new EventId(505, nameof(InStandByMode)),
47+
"Host is in standby mode");
4848

4949
private static readonly Action<ILogger, Exception> _unhealthyRestart =
5050
LoggerMessage.Define(
51-
LogLevel.Error,
52-
new EventId(506, nameof(UnhealthyRestart)),
53-
"Host is unhealthy. Initiating a restart.");
51+
LogLevel.Error,
52+
new EventId(506, nameof(UnhealthyRestart)),
53+
"Host is unhealthy. Initiating a restart.");
5454

5555
private static readonly Action<ILogger, Exception> _stopping =
5656
LoggerMessage.Define(
57-
LogLevel.Information,
58-
new EventId(507, nameof(Stopping)),
59-
"Stopping host...");
57+
LogLevel.Information,
58+
new EventId(507, nameof(Stopping)),
59+
"Stopping host...");
6060

6161
private static readonly Action<ILogger, Exception> _didNotShutDown =
6262
LoggerMessage.Define(
63-
LogLevel.Warning,
64-
new EventId(508, nameof(DidNotShutDown)),
65-
"Host did not shutdown within its allotted time.");
63+
LogLevel.Warning,
64+
new EventId(508, nameof(DidNotShutDown)),
65+
"Host did not shutdown within its allotted time.");
6666

67-
private static readonly Action<ILogger, Exception> _shutDownCompleted =
67+
private static readonly Action<ILogger, Exception> _shutDownCompleted =
6868
LoggerMessage.Define(
69-
LogLevel.Information,
70-
new EventId(509, nameof(ShutDownCompleted)),
71-
"Host shutdown completed.");
69+
LogLevel.Information,
70+
new EventId(509, nameof(ShutDownCompleted)),
71+
"Host shutdown completed.");
7272

7373
private static readonly Action<ILogger, string, Exception> _skipRestart =
7474
LoggerMessage.Define<string>(
75-
LogLevel.Debug,
76-
new EventId(510, nameof(SkipRestart)),
77-
"Host restart was requested, but current host state is '{state}'. Skipping restart.");
75+
LogLevel.Debug,
76+
new EventId(510, nameof(SkipRestart)),
77+
"Host restart was requested, but current host state is '{state}'. Skipping restart.");
7878

7979
private static readonly Action<ILogger, Exception> _restarting =
8080
LoggerMessage.Define(
81-
LogLevel.Information,
82-
new EventId(511, nameof(Restarting)),
83-
"Restarting host.");
81+
LogLevel.Information,
82+
new EventId(511, nameof(Restarting)),
83+
"Restarting host.");
8484

8585
private static readonly Action<ILogger, Exception> _restarted =
8686
LoggerMessage.Define(
87-
LogLevel.Information,
88-
new EventId(512, nameof(Restarted)),
89-
"Host restarted.");
87+
LogLevel.Information,
88+
new EventId(512, nameof(Restarted)),
89+
"Host restarted.");
9090

9191
private static readonly Action<ILogger, string, string, Exception> _building =
9292
LoggerMessage.Define<string, string>(
93-
LogLevel.Information,
94-
new EventId(513, nameof(Building)),
95-
"Building host: startup suppressed:{skipHostStartup}, configuration suppressed: {skipHostJsonConfiguration}");
93+
LogLevel.Information,
94+
new EventId(513, nameof(Building)),
95+
"Building host: startup suppressed:{skipHostStartup}, configuration suppressed: {skipHostJsonConfiguration}");
9696

9797
private static readonly Action<ILogger, Exception> _startupWasCanceled =
9898
LoggerMessage.Define(
99-
LogLevel.Debug,
100-
new EventId(514, nameof(StartupWasCanceled)),
101-
"Host startup was canceled.");
99+
LogLevel.Debug,
100+
new EventId(514, nameof(StartupWasCanceled)),
101+
"Host startup was canceled.");
102102

103103
private static readonly Action<ILogger, Exception> _errorOccured =
104104
LoggerMessage.Define(
105-
LogLevel.Debug,
106-
new EventId(515, nameof(ErrorOccured)),
107-
"A host error has occurred");
105+
LogLevel.Error,
106+
new EventId(515, nameof(ErrorOccured)),
107+
"A host error has occurred");
108108

109109
private static readonly Action<ILogger, Exception> _errorOccuredInactive =
110110
LoggerMessage.Define(
111-
LogLevel.Debug,
112-
new EventId(516, nameof(ErrorOccuredInactive)),
113-
"A host error has occurred on an inactive host");
111+
LogLevel.Warning,
112+
new EventId(516, nameof(ErrorOccuredInactive)),
113+
"A host error has occurred on an inactive host");
114114

115115
private static readonly Action<ILogger, Exception> _cancellationRequested =
116116
LoggerMessage.Define(
117-
LogLevel.Debug,
118-
new EventId(517, nameof(CancellationRequested)),
119-
"Cancellation requested. A new host will not be started.");
117+
LogLevel.Debug,
118+
new EventId(517, nameof(CancellationRequested)),
119+
"Cancellation requested. A new host will not be started.");
120+
121+
private static readonly Action<ILogger, string, string, Exception> _activeHostChanging =
122+
LoggerMessage.Define<string, string>(
123+
LogLevel.Debug,
124+
new EventId(518, nameof(ActiveHostChanging)),
125+
"Active host changing from '{oldHostInstanceId}' to '{newHostInstanceId}'.");
126+
127+
private static readonly Action<ILogger, Exception> _enteringRestart =
128+
LoggerMessage.Define(
129+
LogLevel.Debug,
130+
new EventId(519, nameof(EnteringRestart)),
131+
"Restart requested. Cancelling any active host startup.");
120132

121133
public static void ScriptHostServiceInitCanceledByRuntime(this ILogger logger)
122134
{
123-
_scriptHostServiceInitCanceledByRuntime(logger, null);
135+
_scriptHostServiceInitCanceledByRuntime(logger, null);
124136
}
125137

126138
public static void UnhealthyCountExceeded(this ILogger logger, int healthCheckThreshold, TimeSpan healthCheckWindow)
@@ -130,22 +142,22 @@ public static void UnhealthyCountExceeded(this ILogger logger, int healthCheckTh
130142

131143
public static void Offline(this ILogger logger)
132144
{
133-
_offline(logger, null);
145+
_offline(logger, null);
134146
}
135147

136148
public static void Initializing(this ILogger logger)
137149
{
138-
_initializing(logger, null);
150+
_initializing(logger, null);
139151
}
140152

141153
public static void Initialization(this ILogger logger, int attemptCount, int startCount)
142154
{
143-
_initialization(logger, attemptCount, startCount, null);
155+
_initialization(logger, attemptCount, startCount, null);
144156
}
145157

146158
public static void InStandByMode(this ILogger logger)
147159
{
148-
_inStandByMode(logger, null);
160+
_inStandByMode(logger, null);
149161
}
150162

151163
public static void UnhealthyRestart(this ILogger logger)
@@ -155,7 +167,7 @@ public static void UnhealthyRestart(this ILogger logger)
155167

156168
public static void Stopping(this ILogger logger)
157169
{
158-
_stopping(logger, null);
170+
_stopping(logger, null);
159171
}
160172

161173
public static void DidNotShutDown(this ILogger logger)
@@ -165,7 +177,7 @@ public static void DidNotShutDown(this ILogger logger)
165177

166178
public static void ShutDownCompleted(this ILogger logger)
167179
{
168-
_shutDownCompleted(logger, null);
180+
_shutDownCompleted(logger, null);
169181
}
170182

171183
public static void SkipRestart(this ILogger logger, string state)
@@ -175,17 +187,17 @@ public static void SkipRestart(this ILogger logger, string state)
175187

176188
public static void Restarting(this ILogger logger)
177189
{
178-
_restarting(logger, null);
190+
_restarting(logger, null);
179191
}
180192

181193
public static void Restarted(this ILogger logger)
182194
{
183-
_restarted(logger, null);
195+
_restarted(logger, null);
184196
}
185197

186198
public static void Building(this ILogger logger, string skipHostStartup, string skipHostJsonConfiguration)
187199
{
188-
_building(logger, skipHostStartup, skipHostJsonConfiguration, null);
200+
_building(logger, skipHostStartup, skipHostJsonConfiguration, null);
189201
}
190202

191203
public static void StartupWasCanceled(this ILogger logger)
@@ -207,5 +219,15 @@ public static void CancellationRequested(this ILogger logger)
207219
{
208220
_cancellationRequested(logger, null);
209221
}
222+
223+
public static void ActiveHostChanging(this ILogger logger, string oldHostInstanceId, string newHostInstanceId)
224+
{
225+
_activeHostChanging(logger, oldHostInstanceId, newHostInstanceId, null);
226+
}
227+
228+
public static void EnteringRestart(this ILogger logger)
229+
{
230+
_enteringRestart(logger, null);
231+
}
210232
}
211233
}

0 commit comments

Comments
 (0)