Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

global variables have inconsistent behavior? #10

Open
jelazual opened this issue Nov 27, 2024 · 0 comments
Open

global variables have inconsistent behavior? #10

jelazual opened this issue Nov 27, 2024 · 0 comments

Comments

@jelazual
Copy link

jelazual commented Nov 27, 2024

I've been trying to write up a simple ruby page/resource return with basic sessions management.
The methodology is

session = cig.cookies["label"].first
unless session.is_a?(String)
  session = generate_session_string
  add_cookies(session)
end
current_session = $sessions[session]
unless current_session
 current_session = generic_session
 $sessions[session] = current_session
 File.write(session_file_path, JSON.generate($sessions))
end
parse_file_access(current_session)

where current session is a string that can be decoded into an array to determine what classes of access someone has.

This sometimes works perfectly, and sometimes is very unreliable and breaks quickly and easily resulting in a generic session.
I've managed to track down that the global variable for $sessions seems to hold the key value pair temporarily, and then loses it seemingly at random, resulting in a session not found and a return to a generic session.
I've tried being very specific about writing to the session file, and it only reads when the core FCGI script is first loaded, before running FCGI.each_cgi {|cgi| make_page(cgi)}

The rest of registration and login seems to more or less work, but even before tying account name and passwords to session tokens, I was getting the same problems.

Are global variables not supported/functional with fcgi-ng? they seem to work fine as long as nothing writes to them, but as soon as it's written, everything breaks.

I'm not really sure if this is a bug here or if I'm supposed to use a function to synchronize the state of a global variable, but since the session key is uniquely generated on login, and nothing else is going to write to that key at any point in the script, it seems very strange that the global variable loses the key, sometimes right away, and sometimes after a while, with no consistency to when or why.
None of my search queries seem to produce any results either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant