RequestVar registerCleanupFunc only called once?

45 views
Skip to first unread message

Noel Kennedy

unread,
Dec 1, 2011, 7:59:54 AM12/1/11
to Lift
I'm using a RequestVar to provide a service which needs to be disposed
of correctly when it is no longer needed, ie it is not advised to
leave it to the garbage collector to tidy up. Therefore I registered
the RequestVar to clean up after use via the registerCleanupFunc .
However, the behaviour I'm seeing is that for the first use only (1st
http request) the service is shutdown correctly. Any usages after
this don't seem to be clean up properly, ie the lambda I passed to
registerCleanupFunc isnt being called again.

Here is my code:

object HttpDispatchConnection extends RequestVar[Http](new Http()) {
registerCleanupFunc(ignore => is.shutdown())
}


Please advise as to what I am doing wrong!

David Pollak

unread,
Dec 1, 2011, 3:02:54 PM12/1/11
to lif...@googlegroups.com
Looking at the RequestVar cleanup code... it's very, very broken.  Please open a ticket (http://ticket.liftweb.net you must be a watcher of the LiftWeb space on Assembla to open tickets) referencing this thread and assign the ticket to me.


--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code



--
Visi.Pro, Cloud Computing for the Rest of Us http://visi.pro
Lift, the simply functional web framework http://liftweb.net


Noel Kennedy

unread,
Dec 13, 2011, 5:27:37 AM12/13/11
to lif...@googlegroups.com
Posted bug report

Cheers,

Noel

alexmnyc

unread,
Oct 10, 2013, 12:13:03 PM10/10/13
to lif...@googlegroups.com
This is still an issue which seems like a fundamental one considering the wide use of RequestVar throughout framework.

RequestVar lifecycle shutdown is only executed once.


Example:

 object cachedCount extends RequestVar(3) {
    registerCleanupFunc(ignore => println("shutdown"+is))
  }


Upon page refreshes "shutdown3" is printed only once.



Antonio Salazar Cardozo

unread,
Oct 10, 2013, 2:07:25 PM10/10/13
to lif...@googlegroups.com
It's a fundamental issue only if there's reliance on the RequestVar's cleanup stuff throughout the framework.

I have found myself needing or even thinking I need a RequestVar cleanup handler exactly never ;)

That said, if it's there, we should either hide it, blow it away, or fix it. What's your use case?
Thanks,
Antonio

Matt Farmer

unread,
Apr 16, 2016, 11:49:39 AM4/16/16
to Lift
Hi, I'm looking into this since I'm trying to go through outstanding issues.

It looks like in the original issue Noel is instantiating an Http instance per-request. I'm making the assumption
that you're using databinder dispatch or something similar but unless I'm misunderstanding
something that'll create a connection pool per request - which under any significant amount of load will cause
you to reach the file descriptor limit. So, that's almost certainly not a good idea.

That said, if the cleanup logic is broken, that is indeed a problem. The interesting bit for me just looking at this
code it that the "unused request var" alert that gets logged in dev mode has behaved as expected in my
experience. I suspect this related to our use of doWith when pulling those cleanup functions out.

That said, can anyone advocate for the importance of this functionality in vars? I've never had cause to use
it either, which makes me wonder if it's actually needed or if it's something we can nuke.
Reply all
Reply to author
Forward
0 new messages