-
-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Problem
When using the Redis session store, sessions fail to serialize because Anubis.Server.Session contains non-serializable fields:
** (Protocol.UndefinedError) protocol Jason.Encoder not implemented for #PID<0.123.0>The name field in the Session struct can be:
- A PID (e.g.,
#PID<0.123.0>) - An atom (e.g.,
:my_server) - A tuple (e.g.,
{:via, Registry, {MyRegistry, "key"}})
These are valid GenServer.name() types but cannot be JSON-encoded.
Current Workaround
I had to implement a custom Jason.Encoder for Anubis.Server.Session:
defimpl Jason.Encoder, for: Anubis.Server.Session do
def encode(session, opts) do
%{
id: session.id,
protocol_version: session.protocol_version,
initialized: session.initialized,
name: nil, # PIDs can't be deserialized anyway
client_info: session.client_info,
client_capabilities: session.client_capabilities,
log_level: session.log_level,
pending_requests: session.pending_requests
}
|> Jason.Encode.map(opts)
end
endThis works because:
- PIDs/atoms can't be meaningfully restored after a restart anyway
- The
nameis reset when the session is restored (seesession.exrestore logic)
Questions
- Should
Anubis.Server.SessionimplementJason.Encodernatively in the library? - Or should the Redis store handle serialization differently (e.g., using
:erlang.term_to_binaryinstead of JSON)? - Is there a better approach I'm missing?
Environment
- anubis_mcp: 0.16.0
- Redis store: Upstash (with SSL via PR feat(redis): add redix_opts for SSL/TLS support #59)
- Elixir: 1.15+
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working