Skip to content

Commit

Permalink
fix: close conns correctly (#16)
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Tingaikin <denis.tingajkin@xored.com>
  • Loading branch information
denis-tingaikin authored Feb 24, 2021
1 parent 2b7ac95 commit e3a7953
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,6 @@ func main() {
),
)

var connects []*networkservice.Connection

defer func() {
for _, conn := range connects {
closeCtx, cancel := context.WithTimeout(ctx, config.RequestTimeout)
defer cancel()
_, _ = c.Close(closeCtx, conn)
}
}()

// ********************************************************************************
log.FromContext(ctx).Infof("executing phase 6: connect to all passed services (time since start: %s)", time.Since(starttime))
// ********************************************************************************
Expand All @@ -206,12 +196,20 @@ func main() {
Labels: u.Labels(),
},
}

requestCtx, cancel := context.WithTimeout(ctx, config.RequestTimeout)
defer cancel()
_, err = c.Request(requestCtx, request)

resp, err := c.Request(requestCtx, request)
if err != nil {
log.FromContext(ctx).Fatalf("requset has failed: %v", err.Error())
}

defer func() {
closeCtx, cancel := context.WithTimeout(ctx, config.RequestTimeout)
defer cancel()
_, _ = c.Close(closeCtx, resp)
}()
}

<-ctx.Done()
Expand Down

0 comments on commit e3a7953

Please sign in to comment.