Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5807fe0

Browse files
authored
test: prevent TestAgent_ReconnectingPTY connection reporting check from interfering (#20210)
When we added support for connection tracking in the Workspace agent, we modified the ReconnectingPTY tests to add an initial connection that we immediately hang up and check that connections are logged.In the case of `screen`-based pty handling, hanging up the initial connection can race with the initial attachment to the `screen` process, and cause that process to exit early. This leaves subsequent connections to the same session ID to fail.In this PR we just use different pty session IDs so that the initial connections we do to verify logging don't interfere with the rest of the test._Arguably_ it's a bug in our Reconnecting PTY code that hanging up immediately can leave the system in a weird state, but we do eventually recover and error out, so I don't think it's worth trying to fix.
1 parente2076be commit5807fe0

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

‎agent/agent_test.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1807,11 +1807,12 @@ func TestAgent_ReconnectingPTY(t *testing.T) {
18071807

18081808
//nolint:dogsled
18091809
conn,agentClient,_,_,_:=setupAgent(t, agentsdk.Manifest{},0)
1810+
idConnectionReport:=uuid.New()
18101811
id:=uuid.New()
18111812

18121813
// Test that the connection is reported. This must be tested in the
18131814
// first connection because we care about verifying all of these.
1814-
netConn0,err:=conn.ReconnectingPTY(ctx,id,80,80,"bash --norc")
1815+
netConn0,err:=conn.ReconnectingPTY(ctx,idConnectionReport,80,80,"bash --norc")
18151816
require.NoError(t,err)
18161817
_=netConn0.Close()
18171818
assertConnectionReport(t,agentClient,proto.Connection_RECONNECTING_PTY,0,"")

‎agent/reconnectingpty/screen.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
// screenReconnectingPTY provides a reconnectable PTY via `screen`.
2727
typescreenReconnectingPTYstruct {
28+
logger slog.Logger
2829
execer agentexec.Execer
2930
command*pty.Cmd
3031

@@ -62,6 +63,7 @@ type screenReconnectingPTY struct {
6263
// own which causes it to spawn with the specified size.
6364
funcnewScreen(ctx context.Context,logger slog.Logger,execer agentexec.Execer,cmd*pty.Cmd,options*Options)*screenReconnectingPTY {
6465
rpty:=&screenReconnectingPTY{
66+
logger:logger,
6567
execer:execer,
6668
command:cmd,
6769
metrics:options.Metrics,
@@ -173,6 +175,7 @@ func (rpty *screenReconnectingPTY) Attach(ctx context.Context, _ string, conn ne
173175

174176
ptty,process,err:=rpty.doAttach(ctx,conn,height,width,logger)
175177
iferr!=nil {
178+
logger.Debug(ctx,"unable to attach to screen reconnecting pty",slog.Error(err))
176179
iferrors.Is(err,context.Canceled) {
177180
// Likely the process was too short-lived and canceled the version command.
178181
// TODO: Is it worth distinguishing between that and a cancel from the
@@ -182,6 +185,7 @@ func (rpty *screenReconnectingPTY) Attach(ctx context.Context, _ string, conn ne
182185
}
183186
returnerr
184187
}
188+
logger.Debug(ctx,"attached to screen reconnecting pty")
185189

186190
deferfunc() {
187191
// Log only for debugging since the process might have already exited on its
@@ -403,6 +407,7 @@ func (rpty *screenReconnectingPTY) Wait() {
403407
}
404408

405409
func (rpty*screenReconnectingPTY)Close(errerror) {
410+
rpty.logger.Debug(context.Background(),"closing screen reconnecting pty",slog.Error(err))
406411
// The closing state change will be handled by the lifecycle.
407412
rpty.state.setState(StateClosing,err)
408413
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp