You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by Ben Gunter <bg...@cpons.com> on 2005/11/22 00:06:39 UTC
Axis leaking Session objects
Hello all. I'm running Axis 1.3 under Tomcat 5.5.12 on Windows XP and
on Solaris 9. I have deployed a session-scoped service using the
SimpleSessionHandler. I discovered the hard way that SimpleSession
objects are not being recovered by the garbage collector and after some
research found the root of the problem.
It seems that each org.apache.axis.handlers.soap.SOAPService object
maintains a Vector of active sessions associated with it. Likewise,
each org.apache.axis.handlers.SimpleSessionHandler maintains a
Hashtable mapping session IDs to SimpleSession objects. The
SimpleSessionHandler's reaping mechanism works properly, cleaning up
stale sessions by removing them from the activeSessions Hashtable after
they've timed out. The problem is that SOAPService has no such
mechanism, and in fact provides no public method to remove Sessions
from its own private Vector of active sessions. (Incidentally, even
clearSessions() doesn't free the sessions up, just removes an attribute
from each of them.)
To complicate matters further, when the SimpleSessionHandler removes a
Session from activeSessions, it does not call invalidate() on the
session so any properties that have been set on the Session are still
referenced by the Session, which is still referenced by the SOAPService
object. This can cause some major problems -- in my case a file handle
leak that forced a restart about every hour.
I'm sure there's more than one way to correct the problem, but I took
two simple steps. First, I added a public removeSession() method to
SOAPService, like so:
/**
* Remove the given session from its known sessions
*/
public void removeSession(Session session) {
session.remove( this.getName() );
Vector v = (Vector) sessions.get( this.getName() );
if ( v != null ) v.remove( session );
}
And then I inserted a few lines into SimpleSessionHandler's invoke()
method, like so:
(At line 25)
import org.apache.axis.handlers.soap.SOAPService;
...
(At line 137)
SOAPService service = context.getService();
...
(At line 155)
if (service != null)
service.removeSession(session);
Hopefully those line numbers haven't been changed by a formatter or
something. I've attached the output of diff -u just in case you need
it.
My testing shows that with this change in place, the Sessions and all
of their properties get cleaned up properly. I don't, however, know if
this will have some ill side effects that I'm not aware of. I'll let
you folks determine that, since you know much more about the code than
I do.
What might be a better solution would be for SOAPService to maintain a
list of weak references to the sessions instead of strong references.
Then the only thing that would need to change would be a few null
checks here and there.
If SOAPService absolutely must maintain a reference to every Session
ever associated with it, then at a minimum the SimpleSessionHandler
must call Session.invalidate() on expired sessions, which frees all the
properties of the Session. My testing showed that would prevent major
problems, but that the Session objects themselves still don't get freed.
This all leaves me with a couple of questions, if you don't mind...
Why does the Session interface have an invalidate() method but no
corresponding isValid() method?
And more importantly, what is the preferred method of tracking sessions
within Axis? I know you can use HTTP sessions or SOAP header sessions,
but I want to use the preferred method, if there is one.
Thanks a bunch. I have found Axis to be indispensable in my work.
--
Ben Gunter
Re: Axis leaking Session objects
Posted by Davanum Srinivas <da...@gmail.com>.
i'd recommend using HTTP sessions because the soap header based
session tracking is non-standard.
thanks,
dims
On 11/21/05, Ben Gunter <bg...@cpons.com> wrote:
> Hello all. I'm running Axis 1.3 under Tomcat 5.5.12 on Windows XP and
> on Solaris 9. I have deployed a session-scoped service using the
> SimpleSessionHandler. I discovered the hard way that SimpleSession
> objects are not being recovered by the garbage collector and after some
> research found the root of the problem.
>
> It seems that each org.apache.axis.handlers.soap.SOAPService object
> maintains a Vector of active sessions associated with it. Likewise,
> each org.apache.axis.handlers.SimpleSessionHandler maintains a
> Hashtable mapping session IDs to SimpleSession objects. The
> SimpleSessionHandler's reaping mechanism works properly, cleaning up
> stale sessions by removing them from the activeSessions Hashtable after
> they've timed out. The problem is that SOAPService has no such
> mechanism, and in fact provides no public method to remove Sessions
> from its own private Vector of active sessions. (Incidentally, even
> clearSessions() doesn't free the sessions up, just removes an attribute
> from each of them.)
>
> To complicate matters further, when the SimpleSessionHandler removes a
> Session from activeSessions, it does not call invalidate() on the
> session so any properties that have been set on the Session are still
> referenced by the Session, which is still referenced by the SOAPService
> object. This can cause some major problems -- in my case a file handle
> leak that forced a restart about every hour.
>
> I'm sure there's more than one way to correct the problem, but I took
> two simple steps. First, I added a public removeSession() method to
> SOAPService, like so:
>
> /**
> * Remove the given session from its known sessions
> */
> public void removeSession(Session session) {
> session.remove( this.getName() );
> Vector v = (Vector) sessions.get( this.getName() );
> if ( v != null ) v.remove( session );
> }
>
> And then I inserted a few lines into SimpleSessionHandler's invoke()
> method, like so:
>
> (At line 25)
> import org.apache.axis.handlers.soap.SOAPService;
> ...
> (At line 137)
> SOAPService service = context.getService();
> ...
> (At line 155)
>
> if (service != null)
> service.removeSession(session);
>
> Hopefully those line numbers haven't been changed by a formatter or
> something. I've attached the output of diff -u just in case you need
> it.
>
> My testing shows that with this change in place, the Sessions and all
> of their properties get cleaned up properly. I don't, however, know if
> this will have some ill side effects that I'm not aware of. I'll let
> you folks determine that, since you know much more about the code than
> I do.
>
> What might be a better solution would be for SOAPService to maintain a
> list of weak references to the sessions instead of strong references.
> Then the only thing that would need to change would be a few null
> checks here and there.
>
> If SOAPService absolutely must maintain a reference to every Session
> ever associated with it, then at a minimum the SimpleSessionHandler
> must call Session.invalidate() on expired sessions, which frees all the
> properties of the Session. My testing showed that would prevent major
> problems, but that the Session objects themselves still don't get freed.
>
> This all leaves me with a couple of questions, if you don't mind...
>
> Why does the Session interface have an invalidate() method but no
> corresponding isValid() method?
>
> And more importantly, what is the preferred method of tracking sessions
> within Axis? I know you can use HTTP sessions or SOAP header sessions,
> but I want to use the preferred method, if there is one.
>
> Thanks a bunch. I have found Axis to be indispensable in my work.
>
> --
> Ben Gunter
>
>
>
>
>
--
Davanum Srinivas : http://wso2.com/blogs/
Re: Axis leaking Session objects
Posted by Davanum Srinivas <da...@gmail.com>.
oops! Please submit a bug report with the patch :)
thanks,
dims
On 11/21/05, Ben Gunter <bg...@cpons.com> wrote:
> Hello all. I'm running Axis 1.3 under Tomcat 5.5.12 on Windows XP and
> on Solaris 9. I have deployed a session-scoped service using the
> SimpleSessionHandler. I discovered the hard way that SimpleSession
> objects are not being recovered by the garbage collector and after some
> research found the root of the problem.
>
> It seems that each org.apache.axis.handlers.soap.SOAPService object
> maintains a Vector of active sessions associated with it. Likewise,
> each org.apache.axis.handlers.SimpleSessionHandler maintains a
> Hashtable mapping session IDs to SimpleSession objects. The
> SimpleSessionHandler's reaping mechanism works properly, cleaning up
> stale sessions by removing them from the activeSessions Hashtable after
> they've timed out. The problem is that SOAPService has no such
> mechanism, and in fact provides no public method to remove Sessions
> from its own private Vector of active sessions. (Incidentally, even
> clearSessions() doesn't free the sessions up, just removes an attribute
> from each of them.)
>
> To complicate matters further, when the SimpleSessionHandler removes a
> Session from activeSessions, it does not call invalidate() on the
> session so any properties that have been set on the Session are still
> referenced by the Session, which is still referenced by the SOAPService
> object. This can cause some major problems -- in my case a file handle
> leak that forced a restart about every hour.
>
> I'm sure there's more than one way to correct the problem, but I took
> two simple steps. First, I added a public removeSession() method to
> SOAPService, like so:
>
> /**
> * Remove the given session from its known sessions
> */
> public void removeSession(Session session) {
> session.remove( this.getName() );
> Vector v = (Vector) sessions.get( this.getName() );
> if ( v != null ) v.remove( session );
> }
>
> And then I inserted a few lines into SimpleSessionHandler's invoke()
> method, like so:
>
> (At line 25)
> import org.apache.axis.handlers.soap.SOAPService;
> ...
> (At line 137)
> SOAPService service = context.getService();
> ...
> (At line 155)
>
> if (service != null)
> service.removeSession(session);
>
> Hopefully those line numbers haven't been changed by a formatter or
> something. I've attached the output of diff -u just in case you need
> it.
>
> My testing shows that with this change in place, the Sessions and all
> of their properties get cleaned up properly. I don't, however, know if
> this will have some ill side effects that I'm not aware of. I'll let
> you folks determine that, since you know much more about the code than
> I do.
>
> What might be a better solution would be for SOAPService to maintain a
> list of weak references to the sessions instead of strong references.
> Then the only thing that would need to change would be a few null
> checks here and there.
>
> If SOAPService absolutely must maintain a reference to every Session
> ever associated with it, then at a minimum the SimpleSessionHandler
> must call Session.invalidate() on expired sessions, which frees all the
> properties of the Session. My testing showed that would prevent major
> problems, but that the Session objects themselves still don't get freed.
>
> This all leaves me with a couple of questions, if you don't mind...
>
> Why does the Session interface have an invalidate() method but no
> corresponding isValid() method?
>
> And more importantly, what is the preferred method of tracking sessions
> within Axis? I know you can use HTTP sessions or SOAP header sessions,
> but I want to use the preferred method, if there is one.
>
> Thanks a bunch. I have found Axis to be indispensable in my work.
>
> --
> Ben Gunter
>
>
>
>
>
--
Davanum Srinivas : http://wso2.com/blogs/