Make server timeout configurable at compile time

This commit is contained in:
2025-05-19 20:22:46 -04:00
parent 8907fdc36e
commit 4210673b84
3 changed files with 9 additions and 6 deletions
+4 -3
View File
@@ -9,6 +9,7 @@ import (
"net/rpc"
"os"
"os/signal"
"strconv"
"syscall"
"time"
@@ -54,13 +55,13 @@ func Start(passphrase []byte) {
// capture sigterms to ensure listener is closed
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
// create 3-minute inactivity timer
timer := time.NewTimer(3 * time.Minute)
// create inactivity timer
timer := time.NewTimer(time.Duration(Timeout) * time.Second)
killTimer := make(chan struct{})
go func() {
select {
case <-timer.C:
log.Println("Three minutes have passed without any connections. Exiting...")
log.Println(strconv.Itoa(Timeout) + " seconds have passed without any connections. Exiting...")
listener.Close()
os.Exit(0)
case <-killTimer: