mesosphere / kubernetes-mesos

A Kubernetes Framework for Apache Mesos
637 stars 92 forks source link

evaluate use of time.After in non-test case code #311

Open jdef opened 9 years ago

jdef commented 9 years ago

we want to avoid leaking goroutines if we can help it. use of time.After is probably ok in some places, and perhaps should be re-implemented using timers in others: we'll have to evaluate on a case-by-case basis.

$ find plugin/contrib/mesos/ -type f -name '*.go' -exec grep -H -e 'time\.After(' \{\} \; | cut -f1 -d:|grep -v -e '_test.go' |sort|uniq -c|sort -n
      1 plugin/contrib/mesos/pkg/election/etcd_master.go
      1 plugin/contrib/mesos/pkg/queue/historical.go
      1 plugin/contrib/mesos/pkg/scheduler/service/compat_windows.go
      1 plugin/contrib/mesos/pkg/scheduler/service/publish.go
      2 plugin/contrib/mesos/pkg/proc/proc.go
      2 plugin/contrib/mesos/pkg/queue/delay.go
      3 plugin/contrib/mesos/pkg/executor/executor.go
      3 plugin/contrib/mesos/pkg/runtime/util.go
      4 plugin/contrib/mesos/pkg/scheduler/plugin.go
      4 plugin/contrib/mesos/pkg/scheduler/scheduler.go
karlkfi commented 9 years ago

Base on previous experience and https://groups.google.com/forum/#!topic/golang-nuts/A597Btr_0P8 - it's usually advisable to avoid use of time.After in a switch statement. Instead, create a new time.Timer before the loop and make sure it gets closed when the switch exits.