Skip to content

Commit fc83412

Browse files
authored
checkpoint: Fix memory leak in checkpoint serializer (#3481)
- Packer instances can't be kept in memory as they retain memory after used
2 parents 457641f + f3a0cbf commit fc83412

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

libs/checkpoint/langgraph/checkpoint/serde/jsonplus.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pathlib
66
import re
77
from collections import deque
8+
from collections.abc import Sequence
89
from datetime import date, datetime, time, timedelta, timezone
910
from enum import Enum
1011
from inspect import isclass
@@ -16,7 +17,7 @@
1617
IPv6Interface,
1718
IPv6Network,
1819
)
19-
from typing import Any, Callable, Optional, Sequence, Union, cast
20+
from typing import Any, Callable, Optional, Union, cast
2021
from uuid import UUID
2122

2223
import msgpack # type: ignore[import-untyped]
@@ -502,15 +503,5 @@ def _msgpack_ext_hook(code: int, data: bytes) -> Any:
502503
return
503504

504505

505-
ENC_POOL: deque[msgpack.Packer] = deque(maxlen=32)
506-
507-
508506
def _msgpack_enc(data: Any) -> bytes:
509-
try:
510-
enc = ENC_POOL.popleft()
511-
except IndexError:
512-
enc = msgpack.Packer(default=_msgpack_default)
513-
try:
514-
return enc.pack(data)
515-
finally:
516-
ENC_POOL.append(enc)
507+
return msgpack.packb(data, default=_msgpack_default)

libs/checkpoint/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "langgraph-checkpoint"
3-
version = "2.0.15"
3+
version = "2.0.16"
44
description = "Library with base interfaces for LangGraph checkpoint savers."
55
authors = []
66
license = "MIT"

0 commit comments

Comments
 (0)