jaksky
jaksky

Reputation: 3405

Typesafe Config - reference.conf different behavior?

It seems to me that application.conf and reference.conf behaves differently. I do understand that reference.conf is intended as "safe fall back" configuration which works every time and application.conf is specific. However I would expect that configuration loaded from either of those will behave exactly the same in the sense of parsing the configuration.

What I am facing is that if the configuration is in application.conf it works fine and when the same file is renamed to reference.conf it doesn't work.

2015-03-30 11:35:54,603 [DEBUG] [BackEndServices-akka.actor.default-dispatcher-15] [com.ss.rg.service.ad.AdImporterServiceActor]akka.tcp://[email protected]:2551/user/AdImporterService - Snapshot saved successfully - removing messages and snapshots up to 0 and timestamp: 1427708154584
2015-03-30 11:35:55,037 [DEBUG] [BackEndServices-akka.actor.default-dispatcher-4] [spray.can.server.HttpListener]akka.tcp://[email protected]:2551/user/IO-HTTP/listener-0 - Binding to /0.0.0.0:8080
2015-03-30 11:35:55,054 [DEBUG] [BackEndServices-akka.actor.default-dispatcher-15] [akka.io.TcpListener]akka.tcp://[email protected]:2551/system/IO-TCP/selectors/$a/0 - Successfully bound to /0:0:0:0:0:0:0:0:8080
2015-03-30 11:35:55,056 [INFO ] [BackEndServices-akka.actor.default-dispatcher-4] [spray.can.server.HttpListener]akka.tcp://[email protected]:2551/user/IO-HTTP/listener-0 - Bound to /0.0.0.0:8080

Compared to :

2015-03-30 11:48:34,053 [INFO ] [BackEndServices-akka.actor.default-dispatcher-3] [Cluster(akka://BackEndServices)]Cluster(akka://BackEndServices) - Cluster Node [akka.tcp://[email protected]:2551] - Leader is moving node [akka.tcp://[email protected]:2551] to [Up]
2015-03-30 11:48:36,413 [DEBUG] [BackEndServices-akka.actor.default-dispatcher-15] [spray.can.server.HttpListener]akka.tcp://[email protected]:2551/user/IO-HTTP/listener-0 - Binding to "0.0.0.0":8080
2015-03-30 11:48:36,446 [DEBUG] [BackEndServices-akka.actor.default-dispatcher-3] [akka.io.TcpListener]akka.tcp://[email protected]:2551/system/IO-TCP/selectors/$a/0 - Bind failed for TCP channel on endpoint ["0.0.0.0":8080]: java.net.SocketException: Unresolved address
2015-03-30 11:48:36,446 [WARN ] [BackEndServices-akka.actor.default-dispatcher-15] [spray.can.server.HttpListener]akka.tcp://[email protected]:2551/user/IO-HTTP/listener-0 - Bind to "0.0.0.0":8080 failed

The settle difference are double quotes. And my configuration is specified as follows:

akka {
  ... standard akka configuration ...
}

webserver.port = 8080
webserver.bindaddress = "0.0.0.0"

Configuration setting is loaded as follows in code:

  val webserver_port_key = "webserver.port"
  val webserver_bindaddress_key = "webserver.bindaddress"
  protected val webserver_bindaddress = ConfigFactory.load().getString(webserver_bindaddress_key)
  protected val webserver_port = ConfigFactory.load().getInt(webserver_port_key)

Did I missed something? I double checked that the port 8080 is free when reference.conf fails to bind.

Thanks for hints

UPDATE: Start with log-config-on-start = on: - When it is in application.conf

# application.conf: 60-61
"webserver" : {
    # application.conf: 61
    "bindaddress" : "0.0.0.0",
    # application.conf: 60
    "port" : 8080
}

- When it is in reference.conf

# reference.conf: 60-61
"webserver" : {
    # reference.conf: 61
    "bindaddress" : "0.0.0.0",
    # reference.conf: 60
    "port" : 8080
}

Issue found :

# application.properties
"webserver" : {
    # application.properties
    "bindaddress" : "\"0.0.0.0\"",
    # application.properties
    "port" : "8080"
}

Upvotes: 1

Views: 1005

Answers (1)

yǝsʞǝla
yǝsʞǝla

Reputation: 16412

It seems that the bindaddress is of a different type because it shows up differently in logs.

In either case enable Akka full config printing on start with this setting in your config:

log-config-on-start = on

Then compare both configurations to see where they mismatch. They should work the same way if the are the same. I suspect that the way you define bindaddress is different, i.e. String vs some other type.

Upvotes: 1

Related Questions