Skip to content

plm: tickers eventually consume all CPU time #1

@mdempsky

Description

@mdempsky

In (*Plm).masterControl(), there is:

for {
    [...]
    timeout := time.NewTicker(plmDelay) //if we hit this with no data received, we 
                                        //can assume the PLM has finished sending data.
    defer timeout.Stop() // 1) Is this necessary? 2) is this local to the for{}?
    select {
        [...]
        case <-timeout.C:
        [...]
   }

}

To answer #2, no, this is not local to the for{}. The Go spec says defer defers execution until the function returns (http://golang.org/ref/spec#Defer_statements), not merely the block scope ends.

The timeout.Stop() call is necessary, but unfortunately the way you're doing it here will cause a large backlog of time.Tickers to accumulate and keep running because the function never returns. For a one-shot timeout like this, what you really want to use is case <-time.After(plmDelay):.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions