Skip to content

StateManagerDisk silently resets corrupted persisted state #7167

Description

@harsh21234i

Describe the bug

StateManagerDisk.load_state() catches every deserialization exception and returns None without logging or distinguishing corruption from a missing state file. get_state() then treats the corrupted file as a brand-new state and can later overwrite the persisted data with defaults, causing silent backend state loss.

To Reproduce

import asyncio
import tempfile
from pathlib import Path

from reflex.istate.manager.disk import StateManagerDisk
from reflex.istate.manager.token import StateToken


async def main():
    with tempfile.TemporaryDirectory() as tmp:
        manager = StateManagerDisk()
        manager.__dict__["states_directory"] = Path(tmp)
        token = StateToken(ident="client", cls=int)

        manager.token_path(token).write_bytes(b"not-a-pickle")

        print("load_state:", await manager.load_state(token))
        print("get_state:", await manager.get_state(token))

        await manager.close()


asyncio.run(main())

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions