Skip to content

Commit c5d80e6

Browse files
committed
fix: reduce graceful shutdown timeout for improved responsiveness
- Updated the GRACEFUL_SHUTDOWN_TIMEOUT constant from 3 seconds to 1 second. - Enhanced the shutdown process in the client to allow for quicker cleanup and response to interrupts.
1 parent 004336f commit c5d80e6

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

constants/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const (
5151

5252
MAX_TUNNELS_PER_IP = 5
5353
TUNNEL_RECONNECT_TIMEOUT = 3
54-
GRACEFUL_SHUTDOWN_TIMEOUT = 3
54+
GRACEFUL_SHUTDOWN_TIMEOUT = 1
5555
TUNNEL_CREATE_TIMEOUT = 3
5656
REQ_BODY_READ_CHUNK_TIMEOUT = 3
5757
DEST_REQUEST_TIMEOUT = 30

internal/client/main.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,20 @@ func Run(config ConfigOptions) {
392392
logger.Log(constants.YELLOW, "Gracefully shutting down client...")
393393
disconnectMsg := protocol.TunnelMessage{MsgType: protocol.CLIENT_DISCONNECT}
394394
_ = mmarClient.SendMessage(disconnectMsg)
395+
396+
// Cancel context to stop goroutines
395397
cancel()
398+
399+
// Give a short time for cleanup, but don't block unnecessarily
396400
gracefulShutdownTimer := time.NewTimer(constants.GRACEFUL_SHUTDOWN_TIMEOUT * time.Second)
397-
<-gracefulShutdownTimer.C
401+
defer gracefulShutdownTimer.Stop()
402+
403+
// Wait for either the timer or a second interrupt (force quit)
404+
select {
405+
case <-gracefulShutdownTimer.C:
406+
// Normal graceful shutdown completed
407+
case <-sigInt:
408+
// Force quit on second interrupt
409+
logger.Log(constants.RED, "Force quitting...")
410+
}
398411
}

0 commit comments

Comments
 (0)