remotesess

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package remotesess 实现 XOps v2 基于 *ssh.Session 的远端命令与交互式 Shell 会话适配器 (ports.RemoteSession,ADR-009 / ADR-015)。

核心安全与并发不变量:

  • 构造期预绑定 StdinPipe / StdoutPipe / StderrPipe,绝不给 ssh.Session.Stdin/Stdout/Stderr 赋值, 彻底规避 golang.org/x/crypto/ssh 内部孤儿拷贝协程泄漏;
  • 所有 env / pty-req / exec / shell 控制请求、输入输出流泵与 Wait 均受上游 lifeNursery 统一监督, 全包 0 裸 go 语句与零行内 nolint 豁免;
  • 输出泵在达到 CommandPlan.MaxOutputBytes 或 dst.Write 失败后继续排空至 EOF,防 SSH 窗口反压死锁。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session 封装单条 *ssh.Session,实现 ports.RemoteSession;零值恒失败关闭。

func New

func New(lifeNursery *conc.Nursery, isAlive func() bool, sshSess *ssh.Session) (*Session, error)

New 预绑定 StdinPipe / StdoutPipe / StderrPipe 并构造受 lifeNursery 监督的 Session。

func (*Session) Close

func (s *Session) Close() error

Close 幂等关闭远端会话通道、停用本地输出写入、O(1) 关闭借出管道桥接写端并在有界宽限内收敛排空(零泄漏)。

func (*Session) ResizePTY

func (s *Session) ResizePTY(ctx context.Context, size ports.TerminalSize) error

ResizePTY 在 lifeNursery 监督下向远端会话发送 RFC 4254 window-change 窗口尺寸更新请求(防黑洞阻塞)。

func (*Session) Signal

func (s *Session) Signal(ctx context.Context, signal string) error

Signal 在 lifeNursery 监督下向远端进程发送规范化 POSIX 信号(如 "INT"、"TERM"、"KILL",兼容可选 "SIG" 前缀)。

func (*Session) Start

func (s *Session) Start(ctx context.Context, cmd execution.CommandPlan, streams ports.ExecStreams) error

Start 在远端会话通道上渲染并启动不可变 CommandPlan(含可选 PTY、环境变量、脚本 stdin 投递与输出上限截断)。

func (*Session) StartShell

func (s *Session) StartShell(ctx context.Context, streams ports.ExecStreams) error

StartShell 在远端会话通道上启动交互式 Shell(可选 PTY 与环境变量统一由 streams 承载)。

func (*Session) StderrPipe

func (s *Session) StderrPipe() (io.Reader, error)

StderrPipe 在 Start/StartShell 前借出远端标准错误读取管道(与非空 ExecStreams.Stderr 互斥)。 底层由独立 lifeNursery 监督的 io.Pipe 桥接:该流到达 EOF 时立即独立关闭写端(解耦 stdout 与 Wait), 且在 Session.Close 时 O(1) 关闭写端以解除半开 TCP 黑洞下的读取阻塞(ADR-015)。

func (*Session) StdinPipe

func (s *Session) StdinPipe() (io.WriteCloser, error)

StdinPipe 在 Start/StartShell 前借出远端标准输入写入管道(与非空 ExecStreams.Stdin 及 PlanKindScript 互斥)。

func (*Session) StdoutPipe

func (s *Session) StdoutPipe() (io.Reader, error)

StdoutPipe 在 Start/StartShell 前借出远端标准输出读取管道(与非空 ExecStreams.Stdout 互斥)。 底层由独立 lifeNursery 监督的 io.Pipe 桥接:该流到达 EOF 时立即独立关闭写端(解耦 stderr 与 Wait), 且在 Session.Close 时 O(1) 关闭写端以解除半开 TCP 黑洞下的读取阻塞(ADR-015)。

func (*Session) Wait

Wait 在上游连接 lifeNursery 监督下等待远端进程退出、排空输出泵并映射为封闭 execution.ExecutionOutcome。 对端进入半开黑洞且 ctx 取消/超时时立即返回 OutcomeUnknown 与 ctx.Err(),绝不永久挂起。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL