Skip to content

Adjust kafka configs to make connection more resilient - #332

Closed
lstruman wants to merge 2 commits into
developfrom
james-dev
Closed

Adjust kafka configs to make connection more resilient#332
lstruman wants to merge 2 commits into
developfrom
james-dev

Conversation

@lstruman

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI review requested due to automatic review settings July 28, 2026 23:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to improve Kafka connection resiliency (consumer + producer) and make shutdown behavior safer by ordering Kafka/HTTP cleanup to avoid producer “send on closed channel” panics.

Changes:

  • Add configurable Sarama resilience tuning (metadata retries/backoff/refresh, session + heartbeat timeouts, net timeouts) for Kafka consumers and producers.
  • Rework main shutdown sequencing to close consumer groups, wait for consume loops to drain, then close the async producer, and finally stop the HTTP server.
  • Update sample configuration to reflect new Kafka TLS flat keys and resilience knobs; add a test-only SQLite DB path override via env var; bump several indirect deps.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
main.go Moves Kafka producer result handling under context and adds ordered shutdown with consume-loop draining.
kafka/kafka_consumer_group.go Adds Sarama consumer resilience defaults configurable via webconfig.kafka.*.
http/webconfig_server.go Adds Sarama producer resilience defaults and introduces shutdown-aware handling for producer sends/results.
db/sqlite/sqlite_client.go Allows overriding test sqlite DB file path via WEBCONFIG_TESTDB_SQLITE_FILE.
config/sample_webconfig.conf Documents new defaults, adds resilience knobs, and switches Kafka TLS config to flat keys.
go.mod Bumps indirect golang.org/x/* and google.golang.org/grpc versions.
go.sum Corresponding checksum updates for dependency bumps.
Comments suppressed due to low confidence (1)

http/webconfig_server.go:1177

  • This recover() also swallows all panics while sending to the producer input channel. To avoid masking unrelated panics, only swallow the expected shutdown panic and re-panic otherwise.
		sent := func() (ok bool) {
			defer func() {
				if r := recover(); r != nil {
					tfields["error"] = r
					log.WithFields(tfields).Warn("dropped: producer closed during shutdown")
					ok = false
				}
			}()

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread main.go Outdated
Comment on lines 167 to 170
@@ -164,16 +168,34 @@
// it is more or less optional, without this reading from the chan,
// the consumer runs anyway.
<-consumer.Ready
Comment thread main.go
Comment on lines +156 to +161
fmt.Printf("kcgroup.Consumer: topics=|%v|, err=%v, retrying in 2s\n", topics, err)
time.Sleep(2 * time.Second)
if gCtx.Err() != nil {
return nil
}
}
Comment thread http/webconfig_server.go
Comment on lines +1124 to +1133
defer func() {
if r := recover(); r != nil {
if m := s.Metrics(); m != nil {
m.ObserveKafkaProducerErr(s.KafkaProducerTopic(), -1)
}
tfields["logger"] = "kafkaproducer"
tfields["error"] = r
log.WithFields(tfields).Warn("dropped: producer closed during shutdown")
}
}()
Comment thread http/webconfig_server.go
Comment on lines 1234 to 1240
for {
select {
case <-ctx.Done():
return
case success := <-s.Successes():
if success == nil {
continue
Copilot AI review requested due to automatic review settings July 28, 2026 23:46
@lstruman lstruman closed this Jul 28, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants