请教一个关于golang kafka的问题。
我在使用Shopify/sarama这个库去连接kafka时,运行程序报错,报错信息如下:
```
unexpected fault address 0xa31800
fatal error: fault
[signal SIGSEGV: segmentation violation code=0x2 addr=0xa31800 pc=0xa31800]
goroutine 34 [running]:
runtime.throw(0x6ea68e, 0x5)
/paic/dev/oracle/11g/odsz11g/go/src/runtime/panic.go:566 +0x95 fp=0xc4200a2cd8 sp=0xc4200a2cb8
runtime.sigpanic()
/paic/dev/oracle/11g/odsz11g/go/src/runtime/sigpanic_unix.go:27 +0x288 fp=0xc4200a2d30 sp=0xc4200a2cd8
github.com/rcrowley/go-metrics.(*StandardHistogram).Update(0xc4201d6060, 0x1)
/paic/dev/oracle/11g/odsz11g/mygo/src/github.com/rcrowley/go-metrics/histogram.go:199 +0x3d fp=0xc4200a2d50 sp=0xc4200a2d30
github.com/Shopify/sarama.(*Broker).updateRequestLatencyMetrics(0xc4201582c0, 0x166b87)
/paic/dev/oracle/11g/odsz11g/mygo/src/github.com/Shopify/sarama/broker.go:656 +0x9b fp=0xc4200a2d78 sp=0xc4200a2d50
github.com/Shopify/sarama.(*Broker).updateIncomingCommunicationMetrics(0xc4201582c0, 0x24, 0x166b87)
/paic/dev/oracle/11g/odsz11g/mygo/src/github.com/Shopify/sarama/broker.go:636 +0x39 fp=0xc4200a2d98 sp=0xc4200a2d78
github.com/Shopify/sarama.(*Broker).responseReceiver(0xc4201582c0)
/paic/dev/oracle/11g/odsz11g/mygo/src/github.com/Shopify/sarama/broker.go:514 +0x77a fp=0xc4200a2f70 sp=0xc4200a2d98
github.com/Shopify/sarama.(*Broker).(github.com/Shopify/sarama.responseReceiver)-fm()
/paic/dev/oracle/11g/odsz11g/mygo/src/github.com/Shopify/sarama/broker.go:148 +0x2a fp=0xc4200a2f88 sp=0xc4200a2f70
github.com/Shopify/sarama.withRecover(0xc4201d60d0)
/paic/dev/oracle/11g/odsz11g/mygo/src/github.com/Shopify/sarama/utils.go:46 +0x43 fp=0xc4200a2fa8 sp=0xc4200a2f88
runtime.goexit()
/paic/dev/oracle/11g/odsz11g/go/src/runtime/asm_amd64.s:2086 +0x1 fp=0xc4200a2fb0 sp=0xc4200a2fa8
created by github.com/Shopify/sarama.(*Broker).Open.func1
/paic/dev/oracle/11g/odsz11g/mygo/src/github.com/Shopify/sarama/broker.go:148 +0x8ae
```
检查堆栈信息最后看到这里,似乎是每处理一个`producer.Input()` 通道传入的Message,就会进行一次这些Metric的更新。
但是我无法理解的是,为什么更新这个东西会造成这种内存泄露的错呢?有没有大神有过类似的经历?或者说,如何进一步排查问题。
```
func (b *Broker) updateOutgoingCommunicationMetrics(bytes int) {
b.requestRate.Mark(1)
if b.brokerRequestRate != nil {
b.brokerRequestRate.Mark(1)
}
requestSize := int64(bytes)
b.outgoingByteRate.Mark(requestSize)
if b.brokerOutgoingByteRate != nil {
b.brokerOutgoingByteRate.Mark(requestSize)
}
b.requestSize.Update(requestSize)
if b.brokerRequestSize != nil {
b.brokerRequestSize.Update(requestSize)
}
}
```
有疑问加站长微信联系(非本文作者)