Plugging a memory leak in rqlite

My most recent post on Reddit got a reader’s attention, and they remarked that rqlite 5.10.0 memory usage grew during the load test, but no such increase in memory usage was seen during the same testing of 5.6.0. Sure enough, there was a memory leak in 5.10.0.

A quick glance at memory consumption during the test makes it clear — a consistent increase in memory usage throughout the test.

As it happens, functionality added to rqlite since release 5.6.0 made specific use of database-serialization functions, functions which dumped the SQLite database to memory. My suspicions immediately turned to rqlite’s use of sqlite3_serialize().

Plugging the leak

sqlite3_serialize(), by default, allocates memory to store the serialization, and it’s up to the caller to release this memory. But my code wasn’t doing that, but it was easy to fix. A new version of rqlite, v5.10.1, was released, and the load test run again. This time memory consumption remained steady, confirming that the leak had been plugged.

Good practice for next time

With InfluxDB, Grafana, and Telegraf now configured on my development machine, this exercise is a good one to run on all releases going forward. Memory leaks can be subtle, and checking for them empirically can be very effective.

Leave a Reply

Your email address will not be published. Required fields are marked *