https://issues.apache.org/bugzilla/show_bug.cgi?id=46218

           Summary: deadlock on xindice+jetty shutdown
           Product: Xindice
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: critical
          Priority: P2
         Component: Server
        AssignedTo: xindice-dev@xml.apache.org
        ReportedBy: [EMAIL PROTECTED]


When running Xindice using the shipped copy of Jetty (and probably any kind of
servlet container that installs its own shutdown hook), a race exists on
shutdown which can lead to deadlock.

Using the xindice script to stop a running instances sends a TERM to the JVM,
thus causing all hooks registered with Runtime.addShutdownHook() to be
executed. Both Xindice and Jetty register hooks - DatabaseShutdownHandler and
in org.mortbay.jetty.Server respectively.

Deadlock occurs in at least this situation: Jetty's shutdown hook thread starts
running, calls XindiceServlet.destroy(), which calls Database.close(boolean) on
an instance, synchronizing on that instance. DatabaseShutdownHandler's thread
starts running and synchronizes on its set of databases. Jetty's thread in
Database.close(boolean) calls DatabaseShutdownHandler.removeDatabase(), tries
to also synchronize on the handler's set of instances but is blocked, since the
handler has already done so. The handler tries to synchronize on the Database
instance, but is blocked since the Jetty thread has already done so. Bam!
Deadlock.

There may be other orderings of operations that exhibit the same problem.

I'm seeing this once in every 10-20 shutdowns on a RHEL 5 box w/ Java 1.6.0_07.

This can be worked-around by disabling Jetty's shutdown hook, for example, by
passing "-DJETTY_NO_SHUTDOWN_HOOK=true" as an argument to the JVM on startup,
but that could be problematic if any requests are in progress on shutdown.

Disabling Xindice's handler would probably be the correct thing to do when
running embedded in a servlet container that reliably manages its own
lifecycle, but this does not appear possible without with code changes.

A fix might be to add a synchronized shutdown() method somewhere that both
XindiceServlet and DatabaseShutdownHandler can call, thus ensuring that only
one can enter it at a time, and obviating the problem of both trying to do so
at the same time.


-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

Reply via email to