Wait for backend to start before accepting connections

This commit is contained in:
mkwcat
2024-05-05 20:56:27 -04:00
parent 9f9f3b10f8
commit 22a3e1d98b
7 changed files with 89 additions and 86 deletions

View File

@@ -64,21 +64,23 @@ func StartServer() {
panic(err)
}
// Close the listener when the application closes.
defer l.Close()
logging.Notice(ModuleName, "Listening on", address)
go func() {
// Close the listener when the application closes.
defer l.Close()
logging.Notice(ModuleName, "Listening on", address)
for {
// Listen for an incoming connection.
conn, err := l.Accept()
if err != nil {
fmt.Println("Error accepting: ", err.Error())
os.Exit(1)
for {
// Listen for an incoming connection.
conn, err := l.Accept()
if err != nil {
fmt.Println("Error accepting: ", err.Error())
os.Exit(1)
}
// Handle connections in a new goroutine.
go handleRequest(conn)
}
// Handle connections in a new goroutine.
go handleRequest(conn)
}
}()
}
// Handles incoming requests.