Hot deploy on tomcat and FFI?

I’ve just warbled up a Sinatra app, and when I hot deploy it
to tomcat 6 I get:

java.lang.NullPointerException
at com.kenai.jffi.Function.finalize(Function.java:177)
at java.lang.ref.Finalizer.invokeFinalizeMethod(Native Method)
at java.lang.ref.Finalizer.runFinalizer(Finalizer.java:83)
at java.lang.ref.Finalizer.access$100(Finalizer.java:14)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:160)
java.lang.NullPointerException
at com.kenai.jffi.Function.finalize(Function.java:177)
at java.lang.ref.Finalizer.invokeFinalizeMethod(Native Method)
at java.lang.ref.Finalizer.runFinalizer(Finalizer.java:83)
at java.lang.ref.Finalizer.access$100(Finalizer.java:14)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:160)

my guess is this is something to do with FFI. Is it a known bug, and
would I
have the same issue if the app only used pure ruby?

Next question is : how can I tell what gem I’m deploying that is using
FFI?
My Gemfile says:

used by warbler to build war file

source “http://rubygems.org
gem ‘sinatra’
gem ‘json_pure’
gem ‘jruby-openssl’
gem ‘rack’
gem ‘rack-cache’
gem ‘savon’, “=0.7.9”

What version of the JRuby jars are in your war file? If you don’t have
1.5.6, can you try again with the latest release?

There was a bug which had this stack trace reported along with it.
Since we have rejiggered finalizers and selectors in the 1.5.x series,
these might have gone away. Another option would be to disable
native/FFI if you don’t need it. -Djruby.native.enabled=false

http://jira.codehaus.org/browse/JRUBY-4981

/Nick

This is 1.5.6 unfortunately. Do you have the link to the other bug
(was just wondering if it might be tomcat specific).

Sorry to be dumb, but how do I feed the -D option into the warble
command?

I am also experiencing this problem on Glassfish V2.1.1

I am using jruby 1.5.6 and tried the JVM option with no success.

Dick D. wrote in post #967123:

This is 1.5.6 unfortunately. Do you have the link to the other bug
(was just wondering if it might be tomcat specific).

Sorry to be dumb, but how do I feed the -D option into the warble
command?

Thanks Nick. On glassfish, the permgen space eventually runs out after
many hot redeploys. Watching in JConsole, it looks like the number of
classes goes up after each redeploy and doesn’t ever come down very
much. We haven’t noticed any problems with regular use, just redeploys.

The work around is to restart glassfish after every redeploy. This is
reasonable since hot redeploys on glassfish have historically had
problems anyhow.

Sorry I haven’t been able to stick to things in terms of Tomcat but most
of my experience is with glassfish. It appears to be same problem in
both app servers though.

Robert

Nick S. wrote in post #967228:

Do you have any noticeable degradation in functionality that seem to
be due to these stack traces?

/Nick

The errors aren’t just informational, it actually fails to redeploy the
WAR
(it’s deployed as ROOT.war in my case, not sure if that effects the
contextAddress variable).
My PermGen is teeny though, that may be what’s making the deploy
fail. I’ll try raising that and see if it helps.

You’d have to configure it to be applied as Tomcat starts up, so it
takes effect in the Tomcat JVM. Although it appears from Robert’s post
that perhaps it doesn’t take any effect.

Perhaps there are some places where FFI functions are being created
even though native isn’t enabled. It might be a bug, not sure.

In the JFFI source code for Function.java, there is this:

protected void finalize() throws Throwable {
    try {
        if (contextAddress != 0 && !disposed) {
            Foreign.getInstance().freeFunction(contextAddress);
        }
    } catch (Throwable t) {

line 177:-----> t.printStackTrace(System.err);
} finally {
super.finalize();
}
}

So in fact it might be safe to ignore these errors, and we should
probably suppress the stack trace output.

Do you have any noticeable degradation in functionality that seem to
be due to these stack traces?

/Nick

Ah - in my case, the WAR does redeploy.
I just upped my permgen and heap, let tomcat deploy onec, then touch
ROOT.war, I get:

INFO: Undeploying context []
Dec 8, 2010 7:55:25 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive ROOT.war

… 18 of these errors
java.lang.NullPointerException
at com.kenai.jffi.Function.finalize(Function.java:177)

then the startup messages from the servlet initializing.
Not sure what’s magic about the number 18…?