Conversation
There was a problem hiding this comment.
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 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 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 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 on lines
1234
to
1240
| for { | ||
| select { | ||
| case <-ctx.Done(): | ||
| return | ||
| case success := <-s.Successes(): | ||
| if success == nil { | ||
| continue |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.