@@ -35,7 +35,6 @@ public sealed class WebHostResolver : IDisposable
35
35
private ILoggerFactory _defaultLoggerFactory ;
36
36
private TraceWriter _defaultTraceWriter ;
37
37
private Timer _specializationTimer ;
38
- private ILogger _logger ;
39
38
40
39
public WebHostResolver ( ScriptSettingsManager settingsManager , ISecretManagerFactory secretManagerFactory , IScriptEventManager eventManager )
41
40
{
@@ -124,86 +123,74 @@ public WebHookReceiverManager GetWebHookReceiverManager(WebHostSettings settings
124
123
/// </summary>
125
124
internal void EnsureInitialized ( WebHostSettings settings )
126
125
{
127
- ILoggerFactory defaultLoggerFactory = GetDefaultLoggerFactory ( settings ) ;
128
- _logger = defaultLoggerFactory . CreateLogger ( ScriptConstants . LogCategoryHostStartup ) ;
129
- try
126
+ lock ( _syncLock )
130
127
{
131
- lock ( _syncLock )
128
+ // Determine whether we should do normal or standby initialization
129
+ if ( ! WebScriptHostManager . InStandbyMode )
132
130
{
133
- // Determine whether we should do normal or standby initialization
134
- if ( ! WebScriptHostManager . InStandbyMode )
131
+ // We're not in standby mode. There are two cases to consider:
132
+ // 1) We _were_ in standby mode and now we're ready to specialize
133
+ // 2) We're doing non-specialization normal initialization
134
+ if ( _activeHostManager == null &&
135
+ ( _standbyHostManager == null || ( _settingsManager . ContainerReady && _settingsManager . ConfigurationReady ) ) )
135
136
{
136
- // We're not in standby mode. There are two cases to consider:
137
- // 1) We _were_ in standby mode and now we're ready to specialize
138
- // 2) We're doing non-specialization normal initialization
139
- if ( _activeHostManager == null &&
140
- ( _standbyHostManager == null || ( _settingsManager . ContainerReady && _settingsManager . ConfigurationReady ) ) )
141
- {
142
- _logger . LogDebug ( "Not in standby mode.Initializing host" ) ;
137
+ _specializationTimer ? . Dispose ( ) ;
138
+ _specializationTimer = null ;
143
139
144
- _specializationTimer ? . Dispose ( ) ;
145
- _specializationTimer = null ;
140
+ _activeScriptHostConfig = CreateScriptHostConfiguration ( settings ) ;
141
+ var defaultLoggerFactory = GetDefaultLoggerFactory ( settings ) ;
142
+ _activeHostManager = new WebScriptHostManager ( _activeScriptHostConfig , _secretManagerFactory , _eventManager , _settingsManager , settings , defaultLoggerFactory ) ;
143
+ _activeReceiverManager = new WebHookReceiverManager ( _activeHostManager . SecretManager ) ;
144
+ InitializeFileSystem ( _settingsManager . FileSystemIsReadOnly ) ;
146
145
147
- _activeScriptHostConfig = CreateScriptHostConfiguration ( settings ) ;
148
- _activeHostManager = new WebScriptHostManager ( _activeScriptHostConfig , _secretManagerFactory , _eventManager , _settingsManager , settings , defaultLoggerFactory ) ;
149
- _activeReceiverManager = new WebHookReceiverManager ( _activeHostManager . SecretManager ) ;
150
- InitializeFileSystem ( _settingsManager . FileSystemIsReadOnly ) ;
151
-
152
- if ( _standbyHostManager != null )
153
- {
154
- // we're starting the one and only one
155
- // standby mode specialization
156
- _activeScriptHostConfig . TraceWriter . Info ( Resources . HostSpecializationTrace ) ;
146
+ if ( _standbyHostManager != null )
147
+ {
148
+ // we're starting the one and only one
149
+ // standby mode specialization
150
+ _activeScriptHostConfig . TraceWriter . Info ( Resources . HostSpecializationTrace ) ;
157
151
158
- // After specialization, we need to ensure that custom timezone
159
- // settings configured by the user (WEBSITE_TIME_ZONE) are honored.
160
- // DateTime caches timezone information, so we need to clear the cache.
161
- TimeZoneInfo . ClearCachedData ( ) ;
152
+ // After specialization, we need to ensure that custom timezone
153
+ // settings configured by the user (WEBSITE_TIME_ZONE) are honored.
154
+ // DateTime caches timezone information, so we need to clear the cache.
155
+ TimeZoneInfo . ClearCachedData ( ) ;
162
156
163
- // ensure we reinitialize hostname after specialization
164
- HostNameProvider . Reset ( ) ;
165
- }
157
+ // ensure we reinitialize hostname after specialization
158
+ HostNameProvider . Reset ( ) ;
159
+ }
166
160
167
- if ( _standbyHostManager != null )
168
- {
169
- _standbyHostManager . Stop ( ) ;
170
- _standbyHostManager . Dispose ( ) ;
171
- }
172
- _standbyReceiverManager ? . Dispose ( ) ;
173
- _standbyScriptHostConfig = null ;
174
- _standbyHostManager = null ;
175
- _standbyReceiverManager = null ;
161
+ if ( _standbyHostManager != null )
162
+ {
163
+ _standbyHostManager . Stop ( ) ;
164
+ _standbyHostManager . Dispose ( ) ;
176
165
}
166
+ _standbyReceiverManager ? . Dispose ( ) ;
167
+ _standbyScriptHostConfig = null ;
168
+ _standbyHostManager = null ;
169
+ _standbyReceiverManager = null ;
177
170
}
178
- else
171
+ }
172
+ else
173
+ {
174
+ // We're in standby (placeholder) mode. Initialize the standby services.
175
+ if ( _standbyHostManager == null )
179
176
{
180
- // We're in standby (placeholder) mode. Initialize the standby services.
181
- if ( _standbyHostManager == null )
182
- {
183
- _logger . LogDebug ( "In standby mode" ) ;
184
- var standbySettings = CreateStandbySettings ( settings ) ;
185
- _standbyScriptHostConfig = CreateScriptHostConfiguration ( standbySettings , true ) ;
186
- _standbyHostManager = new WebScriptHostManager ( _standbyScriptHostConfig , _secretManagerFactory , _eventManager , _settingsManager , standbySettings , defaultLoggerFactory ) ;
187
- _standbyReceiverManager = new WebHookReceiverManager ( _standbyHostManager . SecretManager ) ;
188
-
189
- InitializeFileSystem ( _settingsManager . FileSystemIsReadOnly ) ;
190
- StandbyManager . Initialize ( _standbyScriptHostConfig ) ;
191
-
192
- // start a background timer to identify when specialization happens
193
- // specialization usually happens via an http request (e.g. scale controller
194
- // ping) but this timer is started as well to handle cases where we
195
- // might not receive a request
196
- _specializationTimer = new Timer ( OnSpecializationTimerTick , settings , 1000 , 1000 ) ;
197
- }
177
+ var standbySettings = CreateStandbySettings ( settings ) ;
178
+ _standbyScriptHostConfig = CreateScriptHostConfiguration ( standbySettings , true ) ;
179
+ var defaultLoggerFactory = GetDefaultLoggerFactory ( settings ) ;
180
+ _standbyHostManager = new WebScriptHostManager ( _standbyScriptHostConfig , _secretManagerFactory , _eventManager , _settingsManager , standbySettings , defaultLoggerFactory ) ;
181
+ _standbyReceiverManager = new WebHookReceiverManager ( _standbyHostManager . SecretManager ) ;
182
+
183
+ InitializeFileSystem ( _settingsManager . FileSystemIsReadOnly ) ;
184
+ StandbyManager . Initialize ( _standbyScriptHostConfig ) ;
185
+
186
+ // start a background timer to identify when specialization happens
187
+ // specialization usually happens via an http request (e.g. scale controller
188
+ // ping) but this timer is started as well to handle cases where we
189
+ // might not receive a request
190
+ _specializationTimer = new Timer ( OnSpecializationTimerTick , settings , 1000 , 1000 ) ;
198
191
}
199
192
}
200
193
}
201
- catch ( Exception initializationException )
202
- {
203
- var errorEventId = new EventId ( 103 , "HostInitializationError" ) ;
204
- _logger . LogError ( errorEventId , initializationException , "Failed to initialize host" ) ;
205
- throw ;
206
- }
207
194
}
208
195
209
196
internal static WebHostSettings CreateStandbySettings ( WebHostSettings settings )
0 commit comments