Skip to content

Cherrypick kafka stability - #335

Merged
lstruman merged 2 commits into
developn-1from
cherrypick-kafka-stability
Jul 31, 2026
Merged

Cherrypick kafka stability#335
lstruman merged 2 commits into
developn-1from
cherrypick-kafka-stability

Conversation

@lstruman

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI review requested due to automatic review settings July 31, 2026 21:58

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 improves Kafka resilience and shutdown behavior to reduce failures during broker restarts, while also updating sample configuration and a small test DB override.

Changes:

  • Reworks Kafka consumer lifecycle/shutdown sequencing in main.go (drain loops, ordered cleanup).
  • Tunes Sarama consumer/producer retry, metadata, heartbeat, and network timeout settings for better broker-restart tolerance.
  • Updates config defaults/sample config and bumps indirect Go dependencies.

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 coordinated shutdown/drain logic.
kafka/kafka_consumer_group.go Adds configurable Sarama consumer resilience tuning (retries, refresh, timeouts, session/heartbeat).
http/webconfig_server.go Adds producer-side resilience tuning and hardens producer send/result handling during shutdown.
db/sqlite/sqlite_client.go Allows overriding the unit-test sqlite DB file via WEBCONFIG_TESTDB_SQLITE_FILE.
config/sample_webconfig.conf Updates sample config keys (Kafka TLS flat keys, resilience knobs, new defaults).
go.mod Bumps indirect dependencies (x/* and grpc).
go.sum Updates checksums for bumped dependencies.

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

Comment thread main.go
Comment on lines +120 to +122
if server.KafkaProducerEnabled() {
go server.HandleKafkaProducerResults(gCtx)
}
Comment thread main.go
Comment on lines +178 to +202
// Single shutdown goroutine with ordered cleanup:
// 1. close consumer groups (signals ConsumeClaim goroutines to stop)
// 2. wait for all consume loops to drain (ensures no goroutine is mid-send)
// 3. close AsyncProducer (safe now that no one sends to its Input channel)
// 4. shut down HTTP server
g.Go(
func() error {
<-gCtx.Done()
fmt.Printf("shutdown: initiating consumer group shutdown\n")
for _, kcgroup := range kcgroups {
if err := kcgroup.Close(); err != nil {
fmt.Fprintf(os.Stderr, "kcgroup.Close() err=%v\n", err)
}
}
consumeWg.Wait()
fmt.Printf("shutdown: all consumer loops drained\n")
if server.KafkaProducerEnabled() {
if err := server.AsyncProducer.Close(); err != nil {
fmt.Fprintf(os.Stderr, "%v AsyncProducer.Close() err=%v\n", time.Now().Format(common.LoggingTimeFormat), err)
}
}
fmt.Printf("shutdown: stopping HTTP server\n")
return server.Shutdown(context.Background())
},
)
Comment on lines +140 to +142
sessionTimeout := time.Duration(conf.GetInt32(prefix+".consumer.session_timeout_sec", defaultSessionTimeoutSec)) * time.Second
sconfig.Consumer.Group.Session.Timeout = sessionTimeout
sconfig.Consumer.Group.Heartbeat.Interval = sessionTimeout / 6
Comment thread http/webconfig_server.go
Comment on lines +1174 to +1183
defer func() {
if r := recover(); r != nil {
if fmt.Sprint(r) != "send on closed channel" {
panic(r)
}
tfields["error"] = r
log.WithFields(tfields).Warn("dropped: producer closed during shutdown")
ok = false
}
}()
@lstruman
lstruman merged commit c0ceec5 into developn-1 Jul 31, 2026
4 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 31, 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