@@ -199,26 +199,11 @@ impl Server {
199
199
loop {
200
200
stream. recv ( ) . await ;
201
201
202
- info ! ( "Received SIGHUP: re-loading config & re-applying migrations ." ) ;
202
+ info ! ( "Received SIGHUP: re-apply migations then re-load config ." ) ;
203
203
204
- // Reload config:
205
- match crate :: config:: load_or_init_config_textproto (
206
- state. data_dir ( ) ,
207
- state. schema_metadata ( ) ,
208
- )
209
- . await
210
- {
211
- Ok ( config) => {
212
- if let Err ( err) = state. validate_and_update_config ( config, None ) . await {
213
- error ! ( "Failed to reload config: {err}" ) ;
214
- }
215
- }
216
- Err ( err) => {
217
- error ! ( "Failed to reload config: {err}" ) ;
218
- }
219
- }
220
-
221
- // Re-apply migrations.
204
+ // Re-apply migrations. This needs to happen before reloading the config, which is
205
+ // consistent with the startup order. Otherwise, we may validate a configuration
206
+ // against a stale database schema.
222
207
let user_migrations_path = state. data_dir ( ) . migrations_path ( ) ;
223
208
match state
224
209
. conn ( )
@@ -229,8 +214,8 @@ impl Server {
229
214
. await
230
215
{
231
216
Err ( err) => {
232
- // NOTE: it's not clear what the best error behavior here is. Should the server continue
233
- // to run when migrations fail?
217
+ // NOTE: it's not clear what the best error behavior here is. Should the server
218
+ // continue to run when migrations fail?
234
219
error ! ( "Failed to apply migrations: {err}" ) ;
235
220
}
236
221
Ok ( _new_db) => {
@@ -246,6 +231,23 @@ impl Server {
246
231
}
247
232
}
248
233
}
234
+
235
+ // Reload config:
236
+ match crate :: config:: load_or_init_config_textproto (
237
+ state. data_dir ( ) ,
238
+ state. schema_metadata ( ) ,
239
+ )
240
+ . await
241
+ {
242
+ Ok ( config) => {
243
+ if let Err ( err) = state. validate_and_update_config ( config, None ) . await {
244
+ error ! ( "Failed to reload config: {err}" ) ;
245
+ }
246
+ }
247
+ Err ( err) => {
248
+ error ! ( "Failed to reload config: {err}" ) ;
249
+ }
250
+ }
249
251
}
250
252
} ) ;
251
253
}
0 commit comments