du8442 2018-12-19 03:56
浏览 84
已采纳

如何在golang中调试特定的api?

my wired situation is, the online service is working now, and everyday i can find a few 500 error reports like below:

2018-12-19 00:00:01     [ERROR] path[/vplay/getIdsInfo/?type=vlist&ids=31105228] err[runtime error: index out of range] stack[
goweb.(*RouterTab).ServeHTTP.func3.1:/home/tanxiaolong/golib/src/goweb/router.go:352
runtime.call64:/usr/local/go/src/runtime/asm_amd64.s:574
runtime.gopanic:/usr/local/go/src/runtime/panic.go:505
runtime.panicindex:/usr/local/go/src/runtime/panic.go:28
models.(*VplayModel).AssembleData:/home/tanxiaolong/golib/src/vplay/models/vplay.go:757
controllers.(*VplayController).GetIdsInfoAction:/home/tanxiaolong/golib/src/vplay/controllers/vplay.go:652
runtime.call32:/usr/local/go/src/runtime/asm_amd64.s:573
reflect.Value.call:/usr/local/go/src/reflect/value.go:447
reflect.Value.Call:/usr/local/go/src/reflect/value.go:308
goweb.(*RouterTab).ServeHTTP.func3:/home/tanxiaolong/golib/src/goweb/router.go:370
runtime.goexit:/usr/local/go/src/runtime/asm_amd64.s:2361]      (goweb/router.go:353)

i can find which api by log, but it returns 200 and correct response data if request it with the same query data as 500 requests by myself or wrk or ab.

i don't know how to debug this bug..

any suggestions on api debugging??

many thanks!

  • 写回答

1条回答 默认 最新

  • duanqi5114 2018-12-19 04:07
    关注

    When you're handling errors you can use:

    err.(*errors.Error).ErrorStack()

    to return the stacktrace. With that you can get the line in which your API in some cases gets an index out of range error.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示