dtxob80644 2014-02-17 16:41
浏览 132
已采纳

运行时崩溃

My go code errors out with a strack trace like this:

unexpected fault address 0x0
fatal error: fault
[signal 0xb code=0x80 addr=0x0 pc=0x407d50]

goroutine 52246872 [running]:
runtime.throw(0xad6a77)
    /usr/local/go/src/pkg/runtime/panic.c:464 +0x69 fp=0xc214d2c1f8
runtime.sigpanic()
    /usr/local/go/src/pkg/runtime/os_linux.c:237 +0xe9 fp=0xc214d2c210
hash_lookup(0x671ec0, 0xc21001eed0, 0xc214d2c2d0)
    /usr/local/go/src/pkg/runtime/hashmap.c:502 +0x150 fp=0xc214d2c290
runtime.mapaccess(0x671ec0, 0xc21001eed0, 0xc214d2c318, 0xc214d2c328, 0xc214d2c330)
    /usr/local/go/src/pkg/runtime/hashmap.c:1004 +0x57 fp=0xc214d2c2c0
runtime.mapaccess2(0x671ec0, 0xc21001eed0, 0x389c, 0x2060009ae, 0xad4dc0, ...)
    /usr/local/go/src/pkg/runtime/hashmap.c:1061 +0x5d fp=0xc214d2c308
growmobile.com/rtb/cache.HistogramCheck(0xc2121eafd0, 0xc, 0xeca93c6a0, 0x852a9f8, 0xad4dc0, ...)
    /mnt/rtb_server/go/src/growmobile.com/rtb/cache/histogram_cache.go:211 +0x16b fp=0xc214d2c798
growmobile.com/rtb/controller.processBidRequest(0xc2121eafd0, 0xc, 0xeca93c6a0, 0x852a9f8, 0xad4dc0, ...)
    /mnt/rtb_server/go/src/growmobile.com/rtb/controller/bidder_logic.go:272 +0x7c2 fp=0xc214d2e928
----- stack segment boundary -----
growmobile.com/rtb/controller.Bid(0x7f7a14250ed8, 0xc2197b3a00, 0xc2157f9dd0)
    /mnt/rtb_server/go/src/growmobile.com/rtb/controller/controller.go:96 +0x903 fp=0x7f79f8dd9da0
net/http.HandlerFunc.ServeHTTP(0x800850, 0x7f7a14250ed8, 0xc2197b3a00, 0xc2157f9dd0)
    /usr/local/go/src/pkg/net/http/server.go:1220 +0x40 fp=0x7f79f8dd9dc0
net/http.(*ServeMux).ServeHTTP(0xc21001e660, 0x7f7a14250ed8, 0xc2197b3a00, 0xc2157f9dd0)
    /usr/local/go/src/pkg/net/http/server.go:1496 +0x163 fp=0x7f79f8dd9df8
net/http.serverHandler.ServeHTTP(0xc21001fa00, 0x7f7a14250ed8, 0xc2197b3a00, 0xc2157f9dd0)
    /usr/local/go/src/pkg/net/http/server.go:1597 +0x16e fp=0x7f79f8dd9e38
net/http.(*conn).serve(0xc215d60a00)
    /usr/local/go/src/pkg/net/http/server.go:1167 +0x7b7 fp=0x7f79f8dd9f98
runtime.goexit()
    /usr/local/go/src/pkg/runtime/proc.c:1394 fp=0x7f79f8dd9fa0
created by net/http.(*Server).Serve
    /usr/local/go/src/pkg/net/http/server.go:1644 +0x28b

goroutine 1 [chan receive]:
main.serve()
    /mnt/rtb_server/go/src/growmobile.com/rtb/rtb_server/rtb_server.go:71 +0x5f0
main.main()
    /mnt/rtb_server/go/src/growmobile.com/rtb/rtb_server/rtb_server.go:86 +0x1d8

At the time it is trying to access a hash which is a struct that maps to a pointer. The hash is a global one and looks like this:

var histogramCache = make(map[model.HistogramKey]*model.HistogramValue)

The access is a very standard access which looks like:

value, ok := histogramCache[key]

I tried to google something similar but could not find it. I do not use cgo or assertions. This is the go version we are using: go version go1.2 linux/amd64

Thank you, any help would be appreciated.

  • 写回答

2条回答 默认 最新

  • duanbei1903 2014-02-17 17:44
    关注

    Maps are not safe for concurrent access. This might very well be the reason why your code is failing.

    Use a central goroutine (see this example) and retrieve things using channels or use locking tools from sync.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数