I have found wf:session values dont get discarded after application:stop(nitrogen).
The clients can still access the data.
Session handler uses process_registry_handler which dont implement this kind of selection. They only do K/V match. I dont think nproc_registry_handler could ever
support this broad selection. Gproc_registry_handler seems to be possible as it does a qlc query there...
I have shoot myself many times the last month testing an app, I reinitialize the database tables, I stop/start nitrogen again, but the clients will reference the now non-existing
data in their wf:session/wf:user. It has been a nightmare to find myself looking in complete awe for 30 minutes not understanding why my code crashes for no apparent reason.
So, now I'm wrapping session data with:
-define(SESSION_HASH, persistent_term:get(session_hash, nohash)).
session(K, V) -> wf:session(K, {data, ?SESSION_HASH, V}).
session(K) -> case wf:session(K) of
{data, ?SESSION_HASH, V} -> V;
_ -> undefined
end
And with this hack I can now "cancel" all session data "atomically"
cancel_sessions() ->
persistent_term:put(session_hash, SomeNewRandomHash).
And voila, clients now dont reference non-existing data anymore.
1) Why session data doesnt get discarded after stopping nitrogen. Is this by design?
I dont think I have the time to study the handlers (session and registry handlers) so I will imlement my own on top of ets.
2) What performance do you think I would get implementing session data in ets.