2 hours ago · 7 min read1341 words · Tech · 0 comments

I was writing a controller that watches Kubernetes HPAs and Istio VirtualServices for changes and coordinates between the two. Both watchers feed updates into the same reconciliation loop, and the loop needs to act on whatever the current state is, not replay a backlog of intermediate states it missed while it was busy reconciling. I had the watchers sending over Go channels and the reconciler was falling behind, processing stale HPA specs while a newer one was already queued up behind it. Go channels block by default, and for most workloads that's the right behavior. But in this kind of system where you care about the latest value more than processing every value in order, blocking becomes a liability. I ended up reaching for two patterns to fix this: non-blocking sends with select/default, and the drain-before-send pattern on a buffered channel. They solve related but different problems and which one fits depends on the situation. The Blocking Problem Consider a producer that sends…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.