Skip to content

Commit 4d5fe18

Browse files
jrifedylandreimerink
authored andcommitted
datapath/orchestrator: Make sure calls to Reinitialize() don't deadlock
commit b22b49d ("datapath: Fix error handling in orchestrator reinitialize") changed the logic inside reinitialize such that errChan only receives a value if err != nil, so successful calls to Reinitialize will block forever. Simplify the logic around errChan a bit and make sure that it always receives a value whether or not reinitialize() succeeds or fails. Fixes: b22b49d ("datapath: Fix error handling in orchestrator reinitialize") Signed-off-by: Jordan Rife <jrife@google.com>
1 parent 3023be9 commit 4d5fe18

1 file changed

Lines changed: 12 additions & 20 deletions

File tree

pkg/datapath/orchestrator/orchestrator.go

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ func (o *orchestrator) reconciler(ctx context.Context, health cell.Health) error
214214
}
215215

216216
var (
217-
request reinitializeRequest
217+
request = reinitializeRequest{ctx: ctx}
218218
retryChan <-chan time.Time
219219
)
220220
for {
@@ -247,7 +247,8 @@ func (o *orchestrator) reconciler(ctx context.Context, health cell.Health) error
247247
// Reinitializing is expensive, only do so if the configuration has changed.
248248
prevConfig := o.latestLocalNodeConfig.Load()
249249
if prevConfig == nil || !prevConfig.DeepEqual(&localNodeConfig) {
250-
if err := o.reinitialize(ctx, request, &localNodeConfig); err != nil {
250+
err = o.reinitialize(request.ctx, &localNodeConfig)
251+
if err != nil {
251252
o.params.Log.Warn("Failed to initialize datapath, retrying later",
252253
logfields.Error, err,
253254
logfields.RetryDelay, reinitRetryDuration,
@@ -258,15 +259,14 @@ func (o *orchestrator) reconciler(ctx context.Context, health cell.Health) error
258259
retryChan = nil
259260
health.OK("OK")
260261
}
261-
} else {
262-
// We don't need to reinitialize, but we still need to unblock the requestor if there is one.
263-
if request.errChan != nil {
264-
close(request.errChan)
265-
}
266262
}
267263
}
268264

269-
request = reinitializeRequest{}
265+
if request.errChan != nil {
266+
request.errChan <- err
267+
close(request.errChan)
268+
}
269+
request = reinitializeRequest{ctx: ctx}
270270

271271
select {
272272
case <-ctx.Done():
@@ -315,6 +315,9 @@ func (o *orchestrator) DatapathInitialized() <-chan struct{} {
315315
return o.dpInitialized
316316
}
317317

318+
// Reinitialize makes one attempt to reinitialize the datapath. If that attempt
319+
// is usuccessful, it returns the error that occurred but the orchestrator will
320+
// continue to attempt datapath (re)initiailization until it is successful.
318321
func (o *orchestrator) Reinitialize(ctx context.Context) error {
319322
errChan := make(chan error)
320323
o.trigger <- reinitializeRequest{
@@ -324,11 +327,7 @@ func (o *orchestrator) Reinitialize(ctx context.Context) error {
324327
return <-errChan
325328
}
326329

327-
func (o *orchestrator) reinitialize(ctx context.Context, req reinitializeRequest, localNodeConfig *config.Config) error {
328-
if req.ctx != nil {
329-
ctx = req.ctx
330-
}
331-
330+
func (o *orchestrator) reinitialize(ctx context.Context, localNodeConfig *config.Config) error {
332331
err := o.params.Loader.Reinitialize(
333332
ctx,
334333
localNodeConfig,
@@ -341,13 +340,6 @@ func (o *orchestrator) reinitialize(ctx context.Context, req reinitializeRequest
341340
err = o.params.ConnectorConfig.Reinitialize()
342341
}
343342
if err != nil {
344-
if req.errChan != nil {
345-
select {
346-
case req.errChan <- err:
347-
default:
348-
}
349-
close(req.errChan)
350-
}
351343
return err
352344
}
353345

0 commit comments

Comments
 (0)