gresrun / jesque

An implementation of Resque in Java.
http://gresrun.github.io/jesque
Apache License 2.0
628 stars 131 forks source link

java.net.UnknownHostException thrown when `ip-#-#-#-#` pattern has no reverse lookup #128

Closed charneykaye closed 7 years ago

charneykaye commented 7 years ago

This issue did not appear in our (theoretically at parity with production) Docker-compose setup during local development and integration testing.

However, when deployed to Amazon EC2 via Elastic Beanstalk, this exception is thrown, and there appears to be no way to manually configure Jesque to avoid the issue.

We are currently addressing this at the production deployment configuration layer, because the issue is immediately resolved by adding 127.0.0.1 ip-#-#-#-# to the /etc/hosts file (where #.#.#.# is the IP of the current machine).

However, I am curious why Resque is hard-coded to require this for the simple createName() function while instantiating a worker.

Exception in thread "main" java.lang.RuntimeException: java.net.UnknownHostException: ip-10-1-1-124: ip-10-1-1-124: Name or service not known
        at net.greghaines.jesque.worker.WorkerImpl.createName(WorkerImpl.java:755)
        at net.greghaines.jesque.worker.WorkerImpl.<init>(WorkerImpl.java:195)
        at net.greghaines.jesque.worker.WorkerImpl.<init>(WorkerImpl.java:157)
        at net.greghaines.jesque.worker.WorkerImpl.<init>(WorkerImpl.java:141)
        at io.xj.core.database.redis.impl.RedisDatabaseProviderImpl.getQueueWorker(RedisDatabaseProviderImpl.java:31)
        at io.xj.core.work.impl.WorkManagerImpl.getWorker(WorkManagerImpl.java:68)
        at io.xj.core.app.AppImpl.lambda$start$0(AppImpl.java:95)
        at io.xj.core.work.RobustWorkerPool.<init>(RobustWorkerPool.java:135)
        at io.xj.core.work.RobustWorkerPool.<init>(RobustWorkerPool.java:104)
        at io.xj.core.app.AppImpl.start(AppImpl.java:96)
        at io.xj.worker.Main.main(Main.java:122)
Caused by: java.net.UnknownHostException: ip-10-1-1-124: ip-10-1-1-124: Name or service not known
        at java.net.InetAddress.getLocalHost(InetAddress.java:1505)
        at net.greghaines.jesque.worker.WorkerImpl.createName(WorkerImpl.java:748)
        ... 10 more
Caused by: java.net.UnknownHostException: ip-10-1-1-124: Name or service not known
        at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
        at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)
        at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
        at java.net.InetAddress.getLocalHost(InetAddress.java:1500)
        ... 11 more
gresrun commented 7 years ago

The name of the worker matches the Resque worker naming scheme defined here: https://github.com/resque/resque/blob/e0f850f087160362cec1ae3759c7c1e1d9190381/lib/resque/worker.rb#L777

You can subclass WorkerImpl and override the createName() method to modify the default behavior if that's easier than modifying the environment.

charneykaye commented 7 years ago

Thanks for the tip @gresrun -- the environment update seemed best overall, and Jesque has been working very well.