@@ -436,13 +436,6 @@ func getOrgSyncPlans(ctx context.Context, client *APIClient, org Organization) (
436
436
return nil , respErr
437
437
}
438
438
439
- // Make sure that we close the response body once we're done with it
440
- defer func () {
441
- if closeErr := response .Body .Close (); closeErr != nil {
442
- subLogger .Error ().Err (closeErr ).Msg ("error closing response body" )
443
- }
444
- }()
445
-
446
439
subLogger .Debug ().Msgf (
447
440
"Decoding JSON data from %q using a limit of %d bytes" ,
448
441
apiURL ,
@@ -455,17 +448,25 @@ func getOrgSyncPlans(ctx context.Context, client *APIClient, org Organization) (
455
448
return nil , decodeErr
456
449
}
457
450
451
+ subLogger .Debug ().
452
+ Str ("api_endpoint" , apiURL ).
453
+ Msg ("Successfully decoded JSON data" )
454
+
455
+ // Close the response body once we're done with it. We explicitly
456
+ // close here vs deferring via closure to prevent accumulating client
457
+ // connections to the API if we need to perform multiple paged
458
+ // requests.
459
+ if closeErr := response .Body .Close (); closeErr != nil {
460
+ subLogger .Error ().Err (closeErr ).Msg ("error closing response body" )
461
+ }
462
+
458
463
// Annotate Sync Plans with specific Org values for convenience.
459
464
for i := range syncPlansQueryResp .SyncPlans {
460
465
syncPlansQueryResp .SyncPlans [i ].OrganizationName = org .Name
461
466
syncPlansQueryResp .SyncPlans [i ].OrganizationLabel = org .Label
462
467
syncPlansQueryResp .SyncPlans [i ].OrganizationTitle = org .Title
463
468
}
464
469
465
- subLogger .Debug ().
466
- Str ("api_endpoint" , apiURL ).
467
- Msg ("Successfully decoded JSON data" )
468
-
469
470
numNewSyncPlans := len (syncPlansQueryResp .SyncPlans )
470
471
numCollectedSyncPlans := len (allSyncPlans )
471
472
numSyncPlansRemaining := syncPlansQueryResp .Subtotal - numCollectedSyncPlans
0 commit comments