mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat(agent/reconnectingpty): allow selecting backend type (#17011)
agent/reconnectingpty: allow specifying backend type cli: exp rpty: automatically select backend based on command
This commit is contained in:
@@ -32,6 +32,8 @@ type Options struct {
|
||||
Timeout time.Duration
|
||||
// Metrics tracks various error counters.
|
||||
Metrics *prometheus.CounterVec
|
||||
// BackendType specifies the ReconnectingPTY backend to use.
|
||||
BackendType string
|
||||
}
|
||||
|
||||
// ReconnectingPTY is a pty that can be reconnected within a timeout and to
|
||||
@@ -64,13 +66,20 @@ func New(ctx context.Context, logger slog.Logger, execer agentexec.Execer, cmd *
|
||||
// runs) but in CI screen often incorrectly claims the session name does not
|
||||
// exist even though screen -list shows it. For now, restrict screen to
|
||||
// Linux.
|
||||
backendType := "buffered"
|
||||
autoBackendType := "buffered"
|
||||
if runtime.GOOS == "linux" {
|
||||
_, err := exec.LookPath("screen")
|
||||
if err == nil {
|
||||
backendType = "screen"
|
||||
autoBackendType = "screen"
|
||||
}
|
||||
}
|
||||
var backendType string
|
||||
switch options.BackendType {
|
||||
case "":
|
||||
backendType = autoBackendType
|
||||
default:
|
||||
backendType = options.BackendType
|
||||
}
|
||||
|
||||
logger.Info(ctx, "start reconnecting pty", slog.F("backend_type", backendType))
|
||||
|
||||
|
||||
@@ -207,8 +207,9 @@ func (s *Server) handleConn(ctx context.Context, logger slog.Logger, conn net.Co
|
||||
s.commandCreator.Execer,
|
||||
cmd,
|
||||
&Options{
|
||||
Timeout: s.timeout,
|
||||
Metrics: s.errorsTotal,
|
||||
Timeout: s.timeout,
|
||||
Metrics: s.errorsTotal,
|
||||
BackendType: msg.BackendType,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user