Skip to content

Commit

Permalink
refactor(cloudmeta): simplifies context cancellation checks
Browse files Browse the repository at this point in the history
  • Loading branch information
VAveryanov8 committed Jan 9, 2025
1 parent 1118222 commit 03a63e4
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions pkg/cloudmeta/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,8 @@ func (cloud *CloudMeta) GetInstanceMetadata(ctx context.Context) (InstanceMetada
go func(provider CloudMetadataProvider) {
meta, err := cloud.runWithTimeout(ctx, provider)

select {
case <-ctx.Done():
if ctx.Err() != nil {
return
default:
}

results <- msg{meta: meta, err: err}
Expand All @@ -105,10 +103,8 @@ func (cloud *CloudMeta) GetInstanceMetadata(ctx context.Context) (InstanceMetada
return InstanceMetadata{}, ctx.Err()
case res := <-results:
// Additional context check just in case messages in results and in ctx.Done channels were available at the same time.
select {
case <-ctx.Done():
return InstanceMetadata{}, ctx.Err()
default:
if err := ctx.Err(); err != nil {
return InstanceMetadata{}, err
}
if res.err != nil {
mErr = multierr.Append(mErr, res.err)
Expand Down

0 comments on commit 03a63e4

Please sign in to comment.