@@ -182,6 +182,9 @@ func cmdRun(fl Flags) (int, error) {
182
182
183
183
undoMaxProcs := setResourceLimits (logger )
184
184
defer undoMaxProcs ()
185
+ // release the local reference to the undo function so it can be GC'd;
186
+ // the deferred call above has already captured the actual function value.
187
+ undoMaxProcs = nil //nolint:ineffassign,wastedassign
185
188
186
189
configFlag := fl .String ("config" )
187
190
configAdapterFlag := fl .String ("adapter" )
@@ -252,12 +255,16 @@ func cmdRun(fl Flags) (int, error) {
252
255
logBuffer .FlushTo (defaultLogger )
253
256
return caddy .ExitCodeFailedStartup , fmt .Errorf ("loading initial config: %v" , err )
254
257
}
258
+ // release the reference to the config so it can be GC'd
259
+ config = nil //nolint:ineffassign,wastedassign
255
260
256
- // at this stage the config will have replaced
257
- // the default logger to the configured one, so
258
- // we can now flush the buffered logs, then log
259
- // that the config is running.
260
- logBuffer .FlushTo (caddy .Log ())
261
+ // at this stage the config will have replaced the
262
+ // default logger to the configured one, so we can
263
+ // log normally, now that the config is running.
264
+ // also clear our ref to the buffer so it can get GC'd
265
+ logger = caddy .Log ()
266
+ defaultLogger = nil //nolint:ineffassign,wastedassign
267
+ logBuffer = nil //nolint:wastedassign,ineffassign
261
268
logger .Info ("serving initial configuration" )
262
269
263
270
// if we are to report to another process the successful start
@@ -273,12 +280,16 @@ func cmdRun(fl Flags) (int, error) {
273
280
return caddy .ExitCodeFailedStartup ,
274
281
fmt .Errorf ("dialing confirmation address: %v" , err )
275
282
}
276
- defer conn .Close ()
277
283
_ , err = conn .Write (confirmationBytes )
278
284
if err != nil {
279
285
return caddy .ExitCodeFailedStartup ,
280
286
fmt .Errorf ("writing confirmation bytes to %s: %v" , pingbackFlag , err )
281
287
}
288
+ // close (non-defer because we `select {}` below)
289
+ // and release references so they can be GC'd
290
+ conn .Close ()
291
+ confirmationBytes = nil //nolint:ineffassign,wastedassign
292
+ conn = nil //nolint:wastedassign,ineffassign
282
293
}
283
294
284
295
// if enabled, reload config file automatically on changes
@@ -306,6 +317,9 @@ func cmdRun(fl Flags) (int, error) {
306
317
}
307
318
}
308
319
320
+ // release the last local logger reference
321
+ logger = nil //nolint:wastedassign,ineffassign
322
+
309
323
select {}
310
324
}
311
325
0 commit comments