-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
New session cannot be destroyed #175
Comments
@oldium I think there are two ways to fix this: you call Perhaps |
I think why we skipped the |
There is a real issue in lua-resty-openidc library. The library accepts either a session configuration (library starts the session) or a started session (application starts the session). Moreover, in case of logout URI the library is responsible for destroying the session. So if the application decides to always pass-in the opened session, it might happen that when user without cookies visits directly the logout URI, the application opens the new session when calling lua-resty-openidc library to handle the call, and the library tries to destroy the session, because this is what it should do on the session at logout URI. There is no session API to know that the session is non-existent (freshly created and not-yet saved) and cannot be destroyed. This is only known to the application by checking the return value of It would be good to behave as no-op in this particular case (destroy on new not-yet-saved session). I think this is a reasonable requirement - simply speaking, you should be able to destroy an opened session (any non-destroyed state). You could also enhance the session API to add the information that the session was new and not yet saved. Anyway, it makes no sense to me to check if it is valid to call destroy on the session, this should be part of the destroy logic. This worked in 3.x, but stopped working in 4.x, so for me this is a regression. |
@oldium, why aren't you then just calling: require("resty.session").destroy([{ ... config ... }]) Meanwhile I can try to make the The API changed for reason, and the old code should be checked. It is not 1:1 with new. Thus we released it as major 4.x release. What I mean is that in some ways the error seems to point that you are using library in non-optimal way. I know, that is hard to know from outside or when coming from old version. I can think about making it more resilient. |
You are in a library, which received already opened session. So what
Because
Yes, please. Please modify the And just a side note - according to
That is fine, I already did this in the |
@oldium, a couple of notes:
Yes, that is what I am thinking. There is In theory you could just do: if session.state == "open" then
session:destroy()
end I think it is easy to say that making We could add api to tell if session is fresh, then you could do: if session:exists() then
session:destroy()
end Or add Of course you can also do: pcall(session.destroy, session) |
Yes, anything like that. And having |
Session created with
local s = require "resty.session".start()
cannot be directly destroyed withs:destroy()
. It fails withSuch session is in state
new
, notopen
, which is checked in thedestroy()
call.This is problem to libraries like lua-resty-openidc, which can get a started session from the application and cannot determine if calling to
s:destroy()
is safe or not.The text was updated successfully, but these errors were encountered: