square / metrics

Metrics Query Engine
Apache License 2.0
170 stars 21 forks source link

Return an empty channel on a nil Timeout #275

Closed drcapulet closed 8 years ago

drcapulet commented 8 years ago

Causing a nil pointer dereference error with an empty TimeoutOwner.

R: @Nathan-Fenner

Nathan-Fenner commented 8 years ago

Receiving on a nil channel should block forever, per Golang spec so this change shouldn't be needed:

For an operand ch of channel type, the value of the receive operation <-ch is the value received from the channel ch. The channel direction must permit receive operations, and the type of the receive operation is the element type of the channel. The expression blocks until a value is available. Receiving from a nil channel blocks forever. A receive operation on a closed channel can always proceed immediately, yielding the element type's zero value after any previously sent values have been received.

drcapulet commented 8 years ago

So the issue is that t *Timeout itself is nil, so t.done tries to access a value on a nil pointer, causing the nil pointer dereference error.

I could easily return a nil channel instead of the make I'm currently using?

Nathan-Fenner commented 8 years ago

Oh, right, that makes sense. I misread the condition.

I think it would be better to return nil here.

drcapulet commented 8 years ago

Updated.