Tried to update JBoss Deployer libraries in JBoss 5.1 from version 2.0.7.GA to 2.0.9.GA, but dependecies on classes in another services did not let me do it. Then i have manually patched lib/jboss-deployers-impl.jar, replacing org.jboss.deployers.plugins.main.MainDeployerImpl class, taken from jboss-deployers-impl-2.0.9.GA.jar. After that, server is working correctly and undeploy order is correct.