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
simon.vergauwen
03/27/2023, 5:36 AM
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
Tung97 Hl
03/27/2023, 6:52 AM
Yes I’m used as JVM target. So can you suggest me how to restart Ktor server correctly?
s
simon.vergauwen
03/27/2023, 8:35 AM
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.
simon.vergauwen
03/27/2023, 8:36 AM
With restarted you mean inside your code right, not killing and restarting the JVM instance? If the latter, I would suggest using SuspendApp.