【问题】我们写的golang程序不定期会抛出fatal error: concurrent map read and map write 的异常

【原因】排查代码,发现是创建session的时候,用到map会引发这个异常,go1.9之前的版本 map都是线程不安全的,在1.9版本之后,引入了sync.Map这种线程安全的map

【解决】把map[interface{}]interface{} 这种声明改为 sync.Map,相关的方法调用也需要修改

【代码】

golang map引发的 【fatal error: concurrent map read and map write】问题解决

【ps】在1.9以前的版本这样修改,启动会报错 session\sess_mem.go:23: undefined: sync.Map,不过在1.9版本的环境打包成二进制的文件,可以在较低版本运行

相关文章:

  • 2022-12-23
  • 2021-12-26
  • 2019-11-27
  • 2021-07-20
  • 2021-10-23
  • 2022-01-28
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-26
  • 2021-09-15
  • 2022-12-23
  • 2022-12-23
  • 2022-03-02
相关资源
相似解决方案