You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2021/05/12 14:20:24 UTC
[GitHub] [trafficcontrol] rawlinp commented on a change in pull request #5836: Call cancel functions to avoid context leaks
rawlinp commented on a change in pull request #5836:
URL: https://github.com/apache/trafficcontrol/pull/5836#discussion_r631081846
##########
File path: traffic_ops/traffic_ops_golang/deliveryservice/acme.go
##########
@@ -159,7 +159,8 @@ func GenerateAcmeCertificates(w http.ResponseWriter, r *http.Request) {
api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, errors.New("deliveryservice.GenerateAcmeCertificates: Traffic Vault is not configured"))
return
}
- ctx, _ := context.WithTimeout(r.Context(), AcmeTimeout)
+ ctx, cancelTx := context.WithTimeout(r.Context(), AcmeTimeout)
+ defer cancelTx()
Review comment:
I'm not sure this is what we want, since this will cancel the context before the spawned goroutine on L208 (which uses the context) has a chance to complete its task.
##########
File path: traffic_ops/traffic_ops_golang/api/api.go
##########
@@ -492,6 +492,7 @@ type APIInfo struct {
ReqID uint64
Version *Version
Tx *sqlx.Tx
+ CancelTx context.CancelFunc
Review comment:
Shouldn't the `APIInfo.Close()` method cancel the context after attempting to commit the DB transaction?
##########
File path: traffic_ops/traffic_ops_golang/deliveryservice/autorenewcerts.go
##########
@@ -102,7 +102,8 @@ func renewCertificates(w http.ResponseWriter, r *http.Request, deprecated bool)
existingCerts = append(existingCerts, ExistingCerts{Version: ds.Version, XmlId: ds.XmlId})
}
- ctx, _ := context.WithTimeout(r.Context(), AcmeTimeout*time.Duration(len(existingCerts)))
+ ctx, cancelTx := context.WithTimeout(r.Context(), AcmeTimeout*time.Duration(len(existingCerts)))
+ defer cancelTx()
Review comment:
I'm not sure this is what we want, since this will cancel the context before the spawned goroutine on L113 (which uses the context) has a chance to complete its task.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org