Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Commit

Permalink
routine: cancel context each loop round
Browse files Browse the repository at this point in the history
This is a bug, best case just a memory leak, for is infinite and
never breaks thus scheduling indefinitely number of defers

Signed-off-by: Wagner Riffel <wgrriffel@gmail.com>
  • Loading branch information
wgrr committed Mar 30, 2020
1 parent 5299620 commit d220553
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ func CompareInfos(currentValues LastValues) bool {
}

func routine(duration time.Duration) {
for {
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
const timeout = time.Second * 2
for ctx, cancel := context.WithTimeout(context.Background(), timeout); ; cancel() {
currentValue, err := GetDataCOVID19(ctx)
if err != nil {
panic(err)
Expand Down

0 comments on commit d220553

Please sign in to comment.