Why do I get a socket connection error when using remote JBoss AS?

If you are running Ubuntu 10.10, read this FAQ!




If you're running your tests with the remote JBoss AS container adapter, you may encounter the following socket connection error (assume here your computer's hostname is myhost):


Caused by: org.jboss.arquillian.spi.DeploymentException: Failed to deploy test.war
   at org.jboss.arquillian.container.jbossas.remote_6.JBossASRemoteContainer.deploy(JBossASRemoteContainer.java:169)
   at org.jboss.arquillian.impl.handler.ContainerDeployer.callback(ContainerDeployer.java:62)
   at org.jboss.arquillian.impl.handler.ContainerDeployer.callback(ContainerDeployer.java:50)
   at org.jboss.arquillian.impl.event.MapEventManager.fire(MapEventManager.java:63)
   ... 18 more
Caused by: java.lang.RuntimeException: java.io.IOException: Can not get connection to server.
      Problem establishing socket connection for InvokerLocator [socket://myhost: 63209/]
   at org.jboss.profileservice.management.client.upload.StreamingDeploymentTarget.transferDeployment(StreamingDeploymentTarget.java:286)
   at org.jboss.profileservice.management.client.upload.StreamingDeploymentTarget.distribute(StreamingDeploymentTarget.java:106)
   at org.jboss.profileservice.management.client.upload.DeploymentProgressImpl.distribute(DeploymentProgressImpl.java:178)
   at org.jboss.profileservice.management.client.upload.DeploymentProgressImpl.run(DeploymentProgressImpl.java:83)
   at org.jboss.arquillian.container.jbossas.remote_6.JBossASRemoteContainer.deploy(JBossASRemoteContainer.java:144)
   ... 21 more


This started happening on Ubuntu 10.10 (and perhaps other versions of Linux). Network Manager overwrites hostname assignments in /etc/hosts when obtaining an address from a DHCP server. In particular, it:



  • inserts the entry for the dynamic IP address in the first line
  • removes the hostname from
  • puts localhost.localdomain before localhost in the entry (may just be an annoyance)


The beginning of the /etc/hosts file ends up looking like this (followed by some IPv6 entries): myhost localhost.localdomain localhost
::1 myhost localhost6.localdomain6 localhost6 myhost


What it comes down to is that Network Manager should not be messing with this file as it wrecks havoc on servers, such as JBoss AS, bound to these addresses.




The only solution we've been able to figure out is to use a cron job as the root user to fixe the file when it gets messed up.


First, create the correct version of /etc/hosts and stick it somewhere, such as /etc/hosts.fixed, and populate it with the following contents (replace myhost with the hostname of your computer, as reported by the hostname command, and the correct IP assignment, as reported by ipconfig):


/etc/hosts.fixed myhost localhost localhost.localdomain
::1 myhost localhost6 localhost6.localdomain6 myhost
## (optional entry); update if assigned a new address from DHCP myhost

## The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost  ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts


Next, create a script named /etc/restore-etc-hosts.sh to replace the /etc/hosts file if Network Manager screws it up:




if [ `grep -c NetworkManager /etc/hosts` -eq 1 ]; then
   cp /etc/hosts.fixed /etc/hosts


Finally, setup a cron job to run this script as often as you like. We recommend every couple of minutes.


*/3 * * * * /etc/restore-etc-hosts.sh


Once the /etc/hosts file is corrected, restart JBoss AS and run the tests again. Your socket connection error should be gone!