用Go STL查询DB引发的内存泄露

本文同时提供以下语言的翻译:English

问题起因

这几天有一个 Go API service 经过定时监控发现占用的内存不断上涨,内存从初始的 70M 一直上升到超过 1G 直到吃光内存退出,基本上就可以断定是存在内存泄露的问题了,但是因为自带垃圾回收的语言出现内存泄露的情况较少,如果存在那一定是大问题,因此有了下文详细的排查过程,为日后处理此类问题积累经验。

阅读更多

Memory Leak Caused by Using Go STL to Query DB

Problem Origin

Recently, a Go API service was found to have continuously increasing memory usage through regular monitoring. The memory usage rose from the initial 70MB to over 1GB until it ran out of memory and crashed. This clearly indicated a memory leak issue. Since memory leaks rarely occur in languages with built-in garbage collection, if there is one, it must be a significant problem. Therefore, the following detailed investigation process was carried out to accumulate experience for handling similar issues in the future.

阅读更多

Go中反序列化后的类型转换问题记录

在 Go 语言的世界中,类型转换基本上都是很显式的,但最近在编写 web 后台的时候需要进行 context 之间的共享传值,常常就会出现 interface{} 的转换,
最常见的做法就是进行 type assertion 来进行转换,正常来讲作为编写者我们都清楚自己数据的具体类型,然鹅,在某些中间步骤之后,我们的原始类型没有变,但是可能
会被中间类型所迷惑

最近发现到的是JSON反序列化时所做的隐式类型转换,起因是对 interface{} 的一次 assertion 报错

阅读更多