Skip to content

Commit b4a5a7f

Browse files
authored
Merge pull request #368 from werf/fix/leaking-goroutines-in-dynamic-tracker
fix: leaking goroutines in dynamic tracker
2 parents f736fad + 78ba12f commit b4a5a7f

File tree

10 files changed

+19
-19
lines changed

10 files changed

+19
-19
lines changed

pkg/tracker/canary/tracker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func NewTracker(name, namespace string, kube kubernetes.Interface, dynamicClient
7777
objectModified: make(chan *v1beta1.Canary),
7878
objectDeleted: make(chan *v1beta1.Canary),
7979
objectFailed: make(chan interface{}, 1),
80-
errors: make(chan error),
80+
errors: make(chan error, 1),
8181

8282
dynamicClient: dynamicClient,
8383
}

pkg/tracker/daemonset/tracker.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func NewTracker(name, namespace string, kube kubernetes.Interface, opts tracker.
103103
resourceModified: make(chan *appsv1.DaemonSet, 1),
104104
resourceDeleted: make(chan *appsv1.DaemonSet, 1),
105105
resourceFailed: make(chan interface{}, 1),
106-
errors: make(chan error),
106+
errors: make(chan error, 1),
107107

108108
podAddedRelay: make(chan *corev1.Pod, 1),
109109
podStatusesRelay: make(chan map[string]pod.PodStatus, 10),
@@ -330,7 +330,7 @@ func (d *Tracker) runPodsInformer(ctx context.Context, object *appsv1.DaemonSet)
330330
}
331331

332332
func (d *Tracker) runPodTracker(ctx context.Context, podName string) error {
333-
errorChan := make(chan error)
333+
errorChan := make(chan error, 1)
334334
doneChan := make(chan struct{})
335335

336336
newCtx, cancelPodCtx := context.WithCancelCause(ctx)

pkg/tracker/deployment/tracker.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func NewTracker(name, namespace string, kube kubernetes.Interface, opts tracker.
110110

111111
ignoreReadinessProbeFailsByContainerName: opts.IgnoreReadinessProbeFailsByContainerName,
112112

113-
errors: make(chan error),
113+
errors: make(chan error, 1),
114114
resourceAdded: make(chan *appsv1.Deployment, 1),
115115
resourceModified: make(chan *appsv1.Deployment, 1),
116116
resourceDeleted: make(chan *appsv1.Deployment, 1),
@@ -463,7 +463,7 @@ func (d *Tracker) runPodsInformer(ctx context.Context, object *appsv1.Deployment
463463
}
464464

465465
func (d *Tracker) runPodTracker(_ctx context.Context, podName, rsName string) error {
466-
errorChan := make(chan error)
466+
errorChan := make(chan error, 1)
467467
doneChan := make(chan struct{})
468468

469469
newCtx, cancelPodCtx := context.WithCancelCause(_ctx)

pkg/tracker/event/informer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func NewEventInformer(trk *tracker.Tracker, resource interface{}) *EventInformer
4747
FullResourceName: trk.FullResourceName,
4848
},
4949
Resource: resource,
50-
Errors: make(chan error),
50+
Errors: make(chan error, 1),
5151
initialEventUids: make(map[types.UID]bool),
5252
}
5353
}

pkg/tracker/job/tracker.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func NewTracker(name, namespace string, kube kubernetes.Interface, opts tracker.
105105
objectModified: make(chan *batchv1.Job),
106106
objectDeleted: make(chan *batchv1.Job),
107107
objectFailed: make(chan interface{}, 1),
108-
errors: make(chan error),
108+
errors: make(chan error, 1),
109109

110110
podAddedRelay: make(chan *corev1.Pod),
111111
podStatusesRelay: make(chan map[string]pod.PodStatus, 10),
@@ -350,7 +350,7 @@ func (job *Tracker) runPodsInformer(ctx context.Context, object *batchv1.Job) {
350350
}
351351

352352
func (job *Tracker) runPodTracker(_ctx context.Context, podName string) error {
353-
errorChan := make(chan error)
353+
errorChan := make(chan error, 1)
354354
doneChan := make(chan struct{})
355355

356356
newCtx, cancelPodCtx := context.WithCancelCause(_ctx)

pkg/tracker/pod/informer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func NewPodsInformer(trk *tracker.Tracker, controller utils.ControllerMetadata)
3333
},
3434
Controller: controller,
3535
PodAdded: make(chan *corev1.Pod, 1),
36-
Errors: make(chan error),
36+
Errors: make(chan error, 1),
3737
}
3838
}
3939

pkg/tracker/pod/tracker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func NewTracker(name, namespace string, kube kubernetes.Interface, opts Options)
129129
objectModified: make(chan *corev1.Pod),
130130
objectDeleted: make(chan *corev1.Pod),
131131
objectFailed: make(chan interface{}, 1),
132-
errors: make(chan error),
132+
errors: make(chan error, 1),
133133
containerDone: make(chan string, 10),
134134
}
135135
}

pkg/tracker/replicaset/informer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func NewReplicaSetInformer(trk *tracker.Tracker, controller utils.ControllerMeta
5959
ReplicaSetAdded: make(chan *appsv1.ReplicaSet, 1),
6060
ReplicaSetModified: make(chan *appsv1.ReplicaSet, 1),
6161
ReplicaSetDeleted: make(chan *appsv1.ReplicaSet, 1),
62-
Errors: make(chan error),
62+
Errors: make(chan error, 1),
6363
}
6464
}
6565

pkg/tracker/statefulset/tracker.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func NewTracker(name, namespace string, kube kubernetes.Interface, opts tracker.
102102
resourceModified: make(chan *appsv1.StatefulSet, 1),
103103
resourceDeleted: make(chan *appsv1.StatefulSet, 1),
104104
resourceFailed: make(chan interface{}, 1),
105-
errors: make(chan error),
105+
errors: make(chan error, 1),
106106

107107
podAddedRelay: make(chan *corev1.Pod, 1),
108108
podStatusesRelay: make(chan map[string]pod.PodStatus, 10),
@@ -336,7 +336,7 @@ func (d *Tracker) runPodsInformer(ctx context.Context, object *appsv1.StatefulSe
336336
}
337337

338338
func (d *Tracker) runPodTracker(_ctx context.Context, podName string) error {
339-
errorChan := make(chan error)
339+
errorChan := make(chan error, 1)
340340
doneChan := make(chan struct{})
341341

342342
newCtx, cancelPodCtx := context.WithCancelCause(_ctx)

pkg/trackers/dyntracker/dynamic_readiness_tracker.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func (t *DynamicReadinessTracker) trackDeployment(ctx context.Context, tracker *
216216
trackCtx, trackCtxCancelFn := watchtools.ContextWithOptionalTimeout(ctx, t.timeout)
217217
defer trackCtxCancelFn()
218218

219-
trackErrCh := make(chan error)
219+
trackErrCh := make(chan error, 1)
220220
go func() {
221221
trackErrCh <- tracker.Track(trackCtx)
222222
}()
@@ -350,7 +350,7 @@ func (t *DynamicReadinessTracker) trackStatefulSet(ctx context.Context, tracker
350350
trackCtx, trackCtxCancelFn := watchtools.ContextWithOptionalTimeout(ctx, t.timeout)
351351
defer trackCtxCancelFn()
352352

353-
trackErrCh := make(chan error)
353+
trackErrCh := make(chan error, 1)
354354
go func() {
355355
trackErrCh <- tracker.Track(trackCtx)
356356
}()
@@ -470,7 +470,7 @@ func (t *DynamicReadinessTracker) trackDaemonSet(ctx context.Context, tracker *d
470470
trackCtx, trackCtxCancelFn := watchtools.ContextWithOptionalTimeout(ctx, t.timeout)
471471
defer trackCtxCancelFn()
472472

473-
trackErrCh := make(chan error)
473+
trackErrCh := make(chan error, 1)
474474
go func() {
475475
trackErrCh <- tracker.Track(trackCtx)
476476
}()
@@ -590,7 +590,7 @@ func (t *DynamicReadinessTracker) trackJob(ctx context.Context, tracker *job.Tra
590590
trackCtx, trackCtxCancelFn := watchtools.ContextWithOptionalTimeout(ctx, t.timeout)
591591
defer trackCtxCancelFn()
592592

593-
trackErrCh := make(chan error)
593+
trackErrCh := make(chan error, 1)
594594
go func() {
595595
trackErrCh <- tracker.Track(trackCtx)
596596
}()
@@ -710,7 +710,7 @@ func (t *DynamicReadinessTracker) trackCanary(ctx context.Context, tracker *cana
710710
trackCtx, trackCtxCancelFn := watchtools.ContextWithOptionalTimeout(ctx, t.timeout)
711711
defer trackCtxCancelFn()
712712

713-
trackErrCh := make(chan error)
713+
trackErrCh := make(chan error, 1)
714714
go func() {
715715
trackErrCh <- tracker.Track(trackCtx)
716716
}()
@@ -796,7 +796,7 @@ func (t *DynamicReadinessTracker) trackGeneric(ctx context.Context, tracker *gen
796796
regularCh := make(chan *generic.ResourceStatus, 100)
797797
eventCh := make(chan *corev1.Event)
798798

799-
trackErrCh := make(chan error)
799+
trackErrCh := make(chan error, 1)
800800
go func() {
801801
trackErrCh <- tracker.Track(trackCtx, t.noActivityTimeout, addedCh, succeededCh, failedCh, regularCh, eventCh)
802802
}()

0 commit comments

Comments
 (0)