When Ktor starts up, I get this error, where could...
# ktor
d
When Ktor starts up, I get this error, where could this be coming from? Is it from the server, or from my JsonRpc client (based on Ktor client)? It doesn't happen locally, only when in my Docker Swarm...
d
which java version are you using on docker?
d
FROM openjdk:8-jre-alpine
And compiled into shadowJar in Jenkins with:
docker run --rm -v gradle-cache:/home/gradle/.gradle -v "$PWD":/home/gradle/project -w /home/gradle/project gradle:4.7.0-jdk8-alpine gradle shadowJar --no-daemon --console plain
Any ideas? 🤔 It's hard to debug such a thing... but since you know the source code better you might have an better educated guess than me... thanks!
d
Looking better at the stacktrace, it seems that the ApplicationEngineEnvironmentReloading tried to execute the module method dynamically, but failed with this Caused by: java.net.ConnectException: Connection refused
can you reproduce it with a small sample that I can try?
c
Do you have an http client? or oauth? Looks like there is a apache http client somewhere that is starting and attempting to connect
Don't you try to use an http client inside of your module main?
d
Yes @cy, I do have one, a JsonRpcClient I made based on Ktor HttpClient... and it tries to connect to the JsonRpc server when the DI (Kodein) loads up... but should that make the whole service loading crash? Here's my client code:
Copy code
class KtorJsonRpcClient(val client: HttpClient, val moshi: Moshi, val endpoint: String): JsonRpcClient {
    override suspend fun <R> invoke(method: String, params: Any, resultType: Type): R {
        val stringResponse = client.get<String>(endpoint) {
            contentType(ContentType.Application.Json)

            body = JsonRpcRequest(1, method, params)
        }

	    val responseType = Types.newParameterizedType(JsonRpcResponse::class.java, resultType)
	    val response = moshi.adapter<JsonRpcResponse<R>>(responseType).fromJson(stringResponse)!!

        if (response.result != null)
            return response.result
        else
            throw response.error!!.run { JsonRpcException(code, message, data) }
    }
}
And I call a login function in my DI
c
So it can't connect due to "connection refused". The question is why does it try to connect at startup
d
I guess that's my problem... the DI must be loading up that service and trying the login before actually getting to a request... thereby crashing the whole server before it even starts... I just didn't understand the connection between the "connection refused" and
InvocationTargetException
at the beginning of the stack trace 🤔
c
InvocationTargetException
is caused by reflection invocation of the main module function
d
So any Exceptions thrown at point of initialization will get that in the stack trace I suppose... thanks!