nsqio / nsq

A realtime distributed messaging platform
https://nsq.io
MIT License
24.72k stars 2.89k forks source link

SpreadWriter: fix flush panic with zero writes #1441

Closed ploxiln closed 1 year ago

ploxiln commented 1 year ago

fixes #1435

Because the only user of this is nsqd/statsd.go, we could just return without sleeping in this case, and the statsd loop has its own ticker to wait on. But I figured, we might as well make SpreadWriter.flush() always take the desired amount of time, it might be less confusing if this is ever reused, and it's not hard.

(Another interesting idea is to just add a zero-byte buf to the list of bufs if it is empty, but that does result in a zero-byte write syscall, which you can detect with netcat ... it's probably fine, but it's a bit weird.)