Hi everyone. I’m using Ktor to make a localhost. I...
# ktor
t
Hi everyone. I’m using Ktor to make a localhost. I want it can be restarted so this is what I have done: • Create embeddedServer • Start it by function start(wait = true) • Stop it by function stop() • Create new instance of embeddedServer then start it again. I don’t know why whenever I restart the server it’s always throw exception: port already in use. Is the port does not released by Ktor or I was doing wrong?
s
What target are you using? On JVM I don't encounter this issue, but on native targets I have also encountered this issue. Perhaps you can try increasing the time of passed to ApplicationEngine.stop for
gracePeriod
and
timeout
.
t
Yes I’m used as JVM target. So can you suggest me how to restart Ktor server correctly?
s
I would try
stop(3, 5, TimeUnit.SECONDS)
but there are some other tickets that suggest you might even need longer times depending on which engine you use.
With restarted you mean inside your code right, not killing and restarting the JVM instance? If the latter, I would suggest using SuspendApp.
t
Thank you I’m checking it