polarismesh/polaris-go

运行polaris-go里的example的circuitbreaker时崩溃报空指针错误

gtyi999 opened this issue · 4 comments

Describe the bug
运行polaris-go里的example的circuitbreaker时崩溃报空指针错误

To Reproduce
分别运行circuitbreaker的provider 和 consumer ,运行两个provider实例,按照readme步骤测试熔断功能,先停止一个provider实例,curl 向 consumer再发起请求,consumer就崩溃了。

Expected behavior
希望能正常测试熔断功能

Environment

  • Version: [master]
  • OS: [centos 7.9]

Additional context
分别运行circuitbreaker的provider 和 consumer ,运行两个provider实例,按照readme步骤测试熔断功能,先停止一个provider实例,curl 向 consumer再发起请求,consumer就崩溃了。

2022/10/21 17:58:27 [errot] send request to 127.0.0.1:28082 fail : Get "http://127.0.0.1:28082/echo": dial tcp 127.0.0.1:28082: connect: connection refused
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x60 pc=0xa53617]

goroutine 84 [running]:
github.com/polarismesh/polaris-go/plugin/statreporter/prometheus.(*PrometheusHandler).handleCircuitBreakGauge(0xc0000a2410, 0x4044e6?, 0xc000394330)
/root/workspace/go/src/polaris-go/plugin/statreporter/prometheus/prometheus_handler.go:228 +0x77
github.com/polarismesh/polaris-go/plugin/statreporter/prometheus.(*PrometheusHandler).ReportStat(0xa0?, 0xc?, {0xd00750?, 0xc000394330?})
/root/workspace/go/src/polaris-go/plugin/statreporter/prometheus/prometheus_handler.go:139 +0x5a
github.com/polarismesh/polaris-go/plugin/statreporter/prometheus.(*PrometheusReporter).ReportStat(0x750000c0000218b8?, 0x0?, {0xd00750?, 0xc000394330?})
/root/workspace/go/src/polaris-go/plugin/statreporter/prometheus/prometheus_reporter.go:84 +0x27
github.com/polarismesh/polaris-go/pkg/flow.(*Engine).SyncReportStat(0xc0000d2ea0, 0x4, {0xd00750, 0xc000394330})
/root/workspace/go/src/polaris-go/pkg/flow/impl.go:344 +0x171
github.com/polarismesh/polaris-go/plugin/localregistry/inmemory.(*LocalCache).UpdateInstances(0xc00040a000, 0xc000286040)
/root/workspace/go/src/polaris-go/plugin/localregistry/inmemory/inmemory.go:577 +0x7a2
github.com/polarismesh/polaris-go/pkg/plugin/localregistry.(*Proxy).UpdateInstances(0xc0003b6448?, 0xc000021c60?)
/root/workspace/go/src/polaris-go/pkg/plugin/localregistry/proxy.go:48 +0x24
github.com/polarismesh/polaris-go/pkg/flow/cbcheck.(*CircuitBreakCallBack).doCircuitBreakForService(0xc000438600, {{0xc0003b6448?, 0x40e6be?}, {0xc000036450?, 0xffffffffffffff04?}}, {0x0, 0x0}, {0xd02e88?, 0xc0001c4a80}, {0xbec320, ...})
/root/workspace/go/src/polaris-go/pkg/flow/cbcheck/ticker.go:135 +0x790
github.com/polarismesh/polaris-go/pkg/flow/cbcheck.(*CircuitBreakRealTimeCallBack).Process(0xc0005480a0)
/root/workspace/go/src/polaris-go/pkg/flow/cbcheck/realtime.go:68 +0x136
github.com/polarismesh/polaris-go/pkg/flow/schedule.(*taskRoutine).runTakePriority(0xc0000a28c0)
/root/workspace/go/src/polaris-go/pkg/flow/schedule/routines.go:139 +0x202
created by github.com/polarismesh/polaris-go/pkg/flow/schedule.(*taskRoutine).start
/root/workspace/go/src/polaris-go/pkg/flow/schedule/routines.go:106 +0x178

我修复下

handleCircuitBreakGauge

是什么原因导致panic?

err := g.engine.SyncReportStat(model.CircuitBreakStat,
&model.CircuitBreakGauge{ChangeInstance: updateInstance, CBStatus: nextCBStatus})

这里原先的逻辑,塞入的是 preCBStatus,会导致 nil panic