mirror of
https://github.com/samsonjs/vibetunnel.git
synced 2026-04-27 15:17:38 +00:00
add connection timeout
This commit is contained in:
parent
d09b7e7495
commit
ec5402b86e
1 changed files with 10 additions and 3 deletions
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -227,7 +228,7 @@ func (s *Server) sendResponse(conn net.Conn, resp *SpawnResponse) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TryConnect attempts to connect to an existing terminal socket server
|
// TryConnect attempts to connect to an existing terminal socket server with timeout
|
||||||
func TryConnect(socketPath string) (net.Conn, error) {
|
func TryConnect(socketPath string) (net.Conn, error) {
|
||||||
if socketPath == "" {
|
if socketPath == "" {
|
||||||
socketPath = DefaultSocketPath
|
socketPath = DefaultSocketPath
|
||||||
|
|
@ -238,12 +239,18 @@ func TryConnect(socketPath string) (net.Conn, error) {
|
||||||
return nil, fmt.Errorf("socket not found: %w", err)
|
return nil, fmt.Errorf("socket not found: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to connect
|
// Try to connect with timeout
|
||||||
conn, err := net.Dial("unix", socketPath)
|
dialer := net.Dialer{
|
||||||
|
Timeout: 5 * time.Second,
|
||||||
|
}
|
||||||
|
conn, err := dialer.Dial("unix", socketPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to connect to socket: %w", err)
|
return nil, fmt.Errorf("failed to connect to socket: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set read/write timeout for ongoing operations
|
||||||
|
conn.SetDeadline(time.Now().Add(30 * time.Second))
|
||||||
|
|
||||||
return conn, nil
|
return conn, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue