clean up sql connections at server shutdown
This commit is contained in:
parent
041b4a517d
commit
55e6b54789
@ -137,6 +137,16 @@ func CloseConnection(id string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func CloseAllConnections() {
|
||||
global.mu.Lock()
|
||||
defer global.mu.Unlock()
|
||||
|
||||
for id, conn := range global.conns {
|
||||
conn.Close()
|
||||
delete(global.conns, id)
|
||||
}
|
||||
}
|
||||
|
||||
// Lua function implementations
|
||||
|
||||
func luaConnect(s *luajit.State) int {
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"time"
|
||||
|
||||
"Moonshark/modules/http"
|
||||
"Moonshark/modules/sql"
|
||||
"Moonshark/state"
|
||||
)
|
||||
|
||||
@ -64,6 +65,7 @@ func runOnce(scriptPath string) {
|
||||
luaState.Close()
|
||||
// Then stop servers (closes worker states)
|
||||
http.StopAllServers()
|
||||
sql.CloseAllConnections()
|
||||
os.Exit(0)
|
||||
}()
|
||||
|
||||
@ -151,6 +153,7 @@ func runWithWatcher(scriptPath string) {
|
||||
fmt.Println("Files changed, restarting...")
|
||||
http.StopAllServers()
|
||||
luaState.Close()
|
||||
sql.CloseAllConnections()
|
||||
time.Sleep(100 * time.Millisecond) // Brief pause for cleanup
|
||||
continue
|
||||
|
||||
@ -158,6 +161,7 @@ func runWithWatcher(scriptPath string) {
|
||||
fmt.Println("\nShutting down...")
|
||||
http.StopAllServers()
|
||||
luaState.Close()
|
||||
sql.CloseAllConnections()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user