From 01a35eb79a2ce76f8cd79c5a0fe2a1d36257ed4d Mon Sep 17 00:00:00 2001 From: davidby-influx <72418212+davidby-influx@users.noreply.github.com> Date: Mon, 12 Aug 2024 18:09:21 -0700 Subject: [PATCH] fix: prevent an infinite loop in measurementFieldSetChangeMgr (#25155) (#25241) The measurementFieldSetChangeMgr has a possibly infinite loop if the writeRequests channel is closed while in the inner loop to consolidate write requests. We need to check for ok on channel receive and exit the loop when ok is false. closes https://github.com/influxdata/influxdb/issues/25151 (cherry picked from commit 176fca2138a856ed54243a17d06e0926d200d382) closes https://github.com/influxdata/influxdb/issues/25152 --- tsdb/shard.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tsdb/shard.go b/tsdb/shard.go index f5d9b3d07af..f63a40dca90 100644 --- a/tsdb/shard.go +++ b/tsdb/shard.go @@ -2020,10 +2020,12 @@ func (fscm *measurementFieldSetChangeMgr) appendToChangesFile(first writeRequest // requests for { select { - case wr := <-fscm.writeRequests: - changes = append(changes, wr.changes) - errorChannels = append(errorChannels, wr.errorReturn) - continue + case wr, ok := <-fscm.writeRequests: + if ok { + changes = append(changes, wr.changes) + errorChannels = append(errorChannels, wr.errorReturn) + continue + } default: } break