panic: interface conversion: interface {} is nil, not chan *sarama.ProducerError
Posted on 2017-11-04 11:01 翔云123456 阅读(3891) 评论(0) 编辑 收藏 举报使用golang kafka sarama 包时,遇到如下问题:
高并发情况下使用同步sync producer,偶尔遇到crash:
panic: interface conversion: interface {} is nil, not chan *sarama.ProducerError
goroutine 413 [running]:
github.com/Shopify/sarama.(*syncProducer).handleSuccesses(0xc420384840)
/home/lanyang/github.com/Shopify/sarama/sync_producer.go:147 +0x139
github.com/Shopify/sarama.handleSuccesses)-fm()
/home/lanyang/src/github.com/Shopify/sarama/sync_producer.go:76 +0x2f
github.com/Shopify/sarama.withRecover(0xc4201d0750)
/home/lanyang/src/github.com/Shopify/sarama/utils.go:43 +0x45
created by github.com/Shopify/sarama.newSyncProducerFromAsyncProducer
/home/lanyang/src/github.com/Shopify/sarama/sync_producer.go:76 +0x112
问题不容易复现,github上已经留言:
https://github.com/Shopify/sarama/issues/785
download
https://github.com/Shopify/sarama
https://shopify.github.io/sarama/
doc
https://godoc.org/github.com/Shopify/sarama
依赖
github.com/davecgh/go-spew
github.com/eapache/go-resiliency
github.com/eapache/go-xerial-snappy
github.com/eapache/queue
github.com/pierrec/lz4
github.com/pierrec/xxHash
github.com/rcrowley/go-metrics
github.com/golang/snappy
如果kafka down掉,又恢复,client 可自动连接上。
异步方式,网络断开后,仍然会从queue,放入producer的channel中,重连后,这些内容丢失。
例子参考
sync
http://legendtkl.com/2016/06/30/kafka-in-action/
https://studygolang.com/articles/7102
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现