I'm trying to write a Go program that basically wraps a Go HTTP server. The wrapper compiles and runs the HTTP server program, then watches the filesystem and recompiles the HTTP server whenever something changes.
The problem I'm seeing, is that the second time the HTTP server is run it always fails due to the port already being in use.
I start the program using exec.Command like this:
cmd = exec.Command("go", "run", "server.go")
And I later kill it using Process.Kill() like this:
cmd.Process.Kill()
But even if I wait 20 seconds after the Kill() call before starting up the server again, it fails with "address already in use".
Why doesn't Process.Kill() release the port? Is there a way I can release the port?