checkpoint: Fix memory leak in checkpoint serializer (#3481)

- Packer instances can't be kept in memory as they retain memory after
used
This commit is contained in:
Nuno Campos
2025-02-18 11:56:15 -08:00
committed by GitHub
2 changed files with 4 additions and 13 deletions
@@ -5,6 +5,7 @@ import json
import pathlib
import re
from collections import deque
from collections.abc import Sequence
from datetime import date, datetime, time, timedelta, timezone
from enum import Enum
from inspect import isclass
@@ -16,7 +17,7 @@ from ipaddress import (
IPv6Interface,
IPv6Network,
)
from typing import Any, Callable, Optional, Sequence, Union, cast
from typing import Any, Callable, Optional, Union, cast
from uuid import UUID
import msgpack # type: ignore[import-untyped]
@@ -502,15 +503,5 @@ def _msgpack_ext_hook(code: int, data: bytes) -> Any:
return
ENC_POOL: deque[msgpack.Packer] = deque(maxlen=32)
def _msgpack_enc(data: Any) -> bytes:
try:
enc = ENC_POOL.popleft()
except IndexError:
enc = msgpack.Packer(default=_msgpack_default)
try:
return enc.pack(data)
finally:
ENC_POOL.append(enc)
return msgpack.packb(data, default=_msgpack_default)
+1 -1
View File
@@ -1,6 +1,6 @@
[tool.poetry]
name = "langgraph-checkpoint"
version = "2.0.15"
version = "2.0.16"
description = "Library with base interfaces for LangGraph checkpoint savers."
authors = []
license = "MIT"