Session usage/issues

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Session usage/issues

Gloria W

Hello,
I am currently playing with cherrypy sessions, and recovery from
crash/failures.
My settings:
server.socket_port = 1234
server.thread_pool = 10
tools.sessions.on = True
tools.sessions.storage_type = "file"
tools.sessions.storage_path = "/usr/local/Test/CherryPy/SessionData"
tools.sessions.timeout = 60

I start the tp main loop, and all is well. I access my login page, then
my app, and all is good.
I then remove the session file, and try to access my application
without logging in again, and cherrypy does not respond to my request.
The browser hangs. strace on cherrypy reveals that it is still running,
but not responding to my request at all.

I was hoping that if somehow the session file got mangled or
disappeared altogether, that cherrypy could recover from this. But it
looks like it doesn't. I exit the browser, and try to get back into the
login screen, and the browser still hangs.

I was hoping cherrypy would treat this as a new session (empty session
data). Is this a reasonable expectation?

Thank you,
Gloria


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups-beta.google.com/group/cherrypy-users
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Session usage/issues

Robert Brewer

Gloria wrote:

> I am currently playing with cherrypy sessions, and recovery from
> crash/failures.
> My settings:
> server.socket_port = 1234
> server.thread_pool = 10
> tools.sessions.on = True
> tools.sessions.storage_type = "file"
> tools.sessions.storage_path = "/usr/local/Test/CherryPy/SessionData"
> tools.sessions.timeout = 60
>
> I start the tp main loop, and all is well. I access my login
> page, then
> my app, and all is good.
> I then remove the session file, and try to access my application
> without logging in again, and cherrypy does not respond to my request.
> The browser hangs. strace on cherrypy reveals that it is
> still running,
> but not responding to my request at all.
>
> I was hoping that if somehow the session file got mangled or
> disappeared altogether, that cherrypy could recover from this. But it
> looks like it doesn't. I exit the browser, and try to get
> back into the
> login screen, and the browser still hangs.
>
> I was hoping cherrypy would treat this as a new session (empty session
> data). Is this a reasonable expectation?

I think it's reasonable. Are there any tracebacks in your cherrypy error
log?


Robert Brewer
System Architect
Amor Ministries
[hidden email]

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups-beta.google.com/group/cherrypy-users
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Session usage/issues

Gloria W

Unfortunately there is nothing in the access or error logs, and nothing
in the redirected cherrypy output. I do notice, however, that if I kill
cherrypy at that moment, when my HTTP session is hanging, HTTP stops
hanging. So, somewhere in cherrypy, it's making HTTP wait for a
response, and never responds but keeps runnning.

The good news is that it is very easy to reproduce.

Thank you in advance,
Gloria


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups-beta.google.com/group/cherrypy-users
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Session usage/issues

Robert Brewer
Gloria wrote:
> So, somewhere in cherrypy, it's making HTTP wait
> for a response, and never responds but keeps runnning.
> The good news is that it is very easy to reproduce.

That is good news. :) If you could create a (hopefully small) demo of the problem and put it in a ticket, that would be a huge help.

http://www.cherrypy.org/newticket (see bottom of that page for guest creds)


Robert Brewer
System Architect
Amor Ministries
[hidden email]


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups-beta.google.com/group/cherrypy-users
-~----------~----~----~----~------~----~------~--~---

winmail.dat (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Session usage/issues

Robert Brewer
Gloria wrote:
> So, somewhere in cherrypy, it's making HTTP wait
> for a response, and never responds but keeps runnning.
> The good news is that it is very easy to reproduce.

and I answered:
> If you could create a (hopefully small) demo of the
> problem and put it in a ticket, that would be a huge help.

That would still be a nice thing, but I think the problem is simply that os.unlink is being called on a file that doesn't exist anymore. I don't mind ignoring the OSError that results from that, but it would be nice to know why you want this behavior so that can go in the docs for the change. Do you have a separate process that is cleaning out session files? Why do that instead of using the builtin cleanup thread?


Robert Brewer
System Architect
Amor Ministries
[hidden email]



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups-beta.google.com/group/cherrypy-users
-~----------~----~----~----~------~----~------~--~---

winmail.dat (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Session usage/issues

Gloria W

It would be great for cherrypy to handle this condition as just a
nonexistent session.

My reason for this testing is to just make it bulletproof. We'll be
installing this app on machines at law firms, where net access to this
data from the outside is forbidden, and even physically impossible. If
a client has this problem, I will not be able to fix it for them. So I
must prove that cherrypy is "idiot-proof" to get it approved as the web
framework of choice for the application I am designing.

If cherrypy cannot recover from a lost session file, it will look
unstable to the client, and to the law firms's system admins, who are
wondering why such a seemingly simple problem causes a failure. It's
not about proper use. It's about improper use, and anticipating the
uninformed user/admin who may inadvertently clean up everything they do
not understand.

Actually, I found with my test program that it only hangs if I do an
internal redirect after removing the session file.

The test files:

default.conf
[global]
server.socket_port = 1111
server.thread_pool = 10
tools.sessions.on = True
tools.sessions.storage_type = "file"
tools.sessions.storage_path = "./SessionData"
tools.sessions.timeout = 60

[/static]
tools.staticdir.on = True
tools.staticdir.dir = "/usr/local/http/2.0.59/htdocs_ssl"


session_test.py:
import cherrypy
TemplatePath='./Templates'

class Login:
        def index(self):
                dbname = cherrypy.session['session_data'] = "test"
                ft=open(TemplatePath + '/login')
                showPage=ft.read()
                ft.close()
                return showPage
        index.exposed = True

        def login_resp(self):
                try:
                        sdata = cherrypy.session.get('session_data')
                        if not sdata:
                                raise
cherrypy.InternalRedirect(TemplatePath + '/')
                                #return "No session file!"

                except (TypeError,KeyError,IndexError):
                        raise cherrypy.InternalRedirect(TemplatePath +
'/')
                        #return "No session data!" +
Handy.get_a_traceback()

                return "Found session data: %s" % sdata
        login_resp.exposed = True

if __name__ == '__main__':
        cherrypy.tree.mount(Login())

        import os.path
        cherrypy.config.update(os.path.join(os.path.dirname(__file__),
'default.conf'))
        cherrypy.server.quickstart()
        cherrypy.engine.start()

Templates/login:
<center>
<h3>Just click this button:</h3>
<form action="login_resp" method="post">
    <br><input type="submit" value="Login"/>
</form>
</center>
SessionData/* starts out empty

To reproduce:

Run session_test.py , click on the html button to create a session
file.
Remove the session file, and refresh the output page. Notice that it
hangs.
Kill it, and uncomment out the return statements, comment out the raise
cherrypy.Internalredirect() statements.
Rerun session_data.py. Notice that it no longer hangs.

Is there something wrong with my InternalRedirect syntax?


Thank you,
Gloria


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups-beta.google.com/group/cherrypy-users
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Session usage/issues

Gloria W

Ok, to clarify, I've narrowed it down to just redirection:

i_redirect.py:
import cherrypy

class Login:
        def index(self):
                raise cherrypy.InternalRedirect('/blah')
        index.exposed = True

if __name__ == '__main__':
        cherrypy.tree.mount(Login())

        import os.path
        cherrypy.config.update(os.path.join(os.path.dirname(__file__),
'default.conf'))
        cherrypy.server.quickstart()
        cherrypy.engine.start()

This hangs all of the time.

Thank you in advance,
Gloria


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups-beta.google.com/group/cherrypy-users
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Session usage/issues

Robert Brewer
Gloria wrote:
> Ok, to clarify, I've narrowed it down to just redirection
> This hangs all of the time.

OK! I can reproduce that easily, and have written a test case. It seems that when we redirect, acquire_lock is called a second time (assuming tools.sessions.locking == 'implicit'), and the FileSession locking isn't re-entrant (like the RamSession is).

There are several ways to fix this; I'm going to sleep on it, but I should have it fixed within 24 hours.


Robert Brewer
System Architect
Amor Ministries
[hidden email]


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups-beta.google.com/group/cherrypy-users
-~----------~----~----~----~------~----~------~--~---

winmail.dat (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Session usage/issues

Gloria W

Oh, beautiful. Thank you so much :)
Gloria


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups-beta.google.com/group/cherrypy-users
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Session usage/issues

Robert Brewer
In reply to this post by Robert Brewer
> There are several ways to fix this; I'm going to
> sleep on it, but I should have it fixed within
> 24 hours.

Fixed in http://www.cherrypy.org/changeset/1407.


Robert Brewer
System Architect
Amor Ministries
[hidden email]



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups-beta.google.com/group/cherrypy-users
-~----------~----~----~----~------~----~------~--~---

winmail.dat (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Session usage/issues

Gloria W

Thank you!
Gloria


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups-beta.google.com/group/cherrypy-users
-~----------~----~----~----~------~----~------~--~---