# [Known Issues] parseSlowLog 内存泄漏导致 TiDB Server 内存一直占用

## Key Words

TiDB, OOM, parseSlowLog,parseDataForSlowLog

## Description

TiDB Server 内存不释放，大量内存消耗在 `parseSlowLog` 和 `parseDataForSlowLog`

## Root Cause

通过 `INFORMATION_SCHEMA.CLUSTER_SLOW_QUERY` 查询大范围的慢日志，还没有结束时，手工取消了; 

或者 dashboard 界面查询大范围的慢日志信息，还没有结束，手工关闭了页面。

由于 `parseSlowLog` 内存泄漏，导致这部分内存无法释放。

Github issue： [https://github.com/pingcap/tidb/issues/32646](https://github.com/pingcap/tidb/issues/32646) 

## Diagnostic Steps

采集火焰图方法

```
curl -G http://{TiDB_IP}:10080/debug/zip?seconds=30" > profile.zip
IP 地址为 TiDB-Server 服务器的 IP，端口为 tidb_status_port 的端口。
```

或者在 Dashboard 界面实例性能分析---→手工分析或者持续分析中，找到 heap 文件信息

1. 查看 heap 文件，大量内存消耗在 `executor.(\*slowQueryRetriever).parseSlowLog，executor.(\*slowQueryRetriever).parseDataForSlowLog`

2. 查看 goroutine 文件，存在类似如下日志

```golang
goroutine 577481180 [chan send, 41269 minutes]:
github.com/pingcap/tidb/executor.(*slowQueryRetriever).parseSlowLog(0xc05f8a9000, 0x42b9d10, 0xc0023fe270, 0x4303f18, 0xc0815ab400, 0xc0005bcf50, 0x40)
        /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/slow_query.go:457 +0x23e
github.com/pingcap/tidb/executor.(*slowQueryRetriever).parseDataForSlowLog(0xc05f8a9000, 0x42b9d10, 0xc0023fe270, 0x4303f18, 0xc0815ab400)
        /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/slow_query.go:193 +0x1d1
created by github.com/pingcap/tidb/executor.(*slowQueryRetriever).initializeAsyncParsing
        /home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/slow_query.go:1080 +0x98
```

## Resolution

1. github issue：[https://github.com/pingcap/tidb/issues/32646](https://github.com/pingcap/tidb/issues/32646) 

2. duplicate with [https://github.com/pingcap/tidb/issues/32656](https://github.com/pingcap/tidb/issues/32656) ，We don't need this PR because [#33960](https://github.com/pingcap/tidb/pull/33960) is merged. 

3. 从官方文档 5.3.2 版本描述中有
   * 修复了查询 INFORMATION_SCHEMA.CLUSTER_SLOW_QUERY 表导致 TiDB 服务器 OOM 的问题，在 Grafana dashboard 中查看慢查询记录的时候可能会触发该问题 [#33893](https://github.com/pingcap/tidb/issues/33893)

4. 需要升级到 v5.3.2，v5.4.1，v6.1.0 以上版本

## Workaround

重启 TiDB Server 释放内存

## Affected Versions

<v5.3.2,<v5.4.1,<v6.1.0