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

Commit4543a3b

Browse files
authored
fix: log after test exit inTestAgent/StartupScript (#1726)
```$ go test ./agent/ -v -run TestAgent/StartupScript -count 1=== RUN TestAgent=== PAUSE TestAgent=== CONT TestAgent=== RUN TestAgent/StartupScript=== PAUSE TestAgent/StartupScript=== CONT TestAgent/StartupScript t.go:56: 2022-05-24 20:22:39.648 [INFO]<agent.go:112>connected--- PASS: TestAgent (0.00s) --- PASS: TestAgent/StartupScript (0.17s)PASSpanic: Log in goroutine after TestAgent/StartupScript has completed: 2022-05-24 20:22:39.651 [WARN]<agent.go:130>agent script failed ..."error": run: github.com/coder/coder/agent.(*agent).runStartupScript /home/colin/Projects/coder/coder/agent/agent.go:183 - signal: killed```
1 parent99c79c7 commit4543a3b

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

‎agent/agent.go

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,25 @@ import (
2121
"time"
2222

2323
"github.com/armon/circbuf"
24+
"github.com/gliderlabs/ssh"
2425
"github.com/google/uuid"
25-
26+
"github.com/pkg/sftp"
2627
"go.uber.org/atomic"
28+
gossh"golang.org/x/crypto/ssh"
29+
"golang.org/x/xerrors"
2730

2831
"cdr.dev/slog"
2932
"github.com/coder/coder/agent/usershell"
3033
"github.com/coder/coder/peer"
3134
"github.com/coder/coder/peerbroker"
3235
"github.com/coder/coder/pty"
3336
"github.com/coder/retry"
37+
)
3438

35-
"github.com/pkg/sftp"
36-
37-
"github.com/gliderlabs/ssh"
38-
gossh"golang.org/x/crypto/ssh"
39-
"golang.org/x/xerrors"
39+
const (
40+
ProtocolReconnectingPTY="reconnecting-pty"
41+
ProtocolSSH="ssh"
42+
ProtocolDial="dial"
4043
)
4144

4245
typeOptionsstruct {
@@ -174,17 +177,25 @@ func (*agent) runStartupScript(ctx context.Context, script string) error {
174177
deferfunc() {
175178
_=writer.Close()
176179
}()
180+
177181
caller:="-c"
178182
ifruntime.GOOS=="windows" {
179183
caller="/c"
180184
}
185+
181186
cmd:=exec.CommandContext(ctx,shell,caller,script)
182187
cmd.Stdout=writer
183188
cmd.Stderr=writer
184189
err=cmd.Run()
185190
iferr!=nil {
191+
// cmd.Run does not return a context canceled error, it returns "signal: killed".
192+
ifctx.Err()!=nil {
193+
returnctx.Err()
194+
}
195+
186196
returnxerrors.Errorf("run: %w",err)
187197
}
198+
188199
returnnil
189200
}
190201

@@ -208,11 +219,11 @@ func (a *agent) handlePeerConn(ctx context.Context, conn *peer.Conn) {
208219
}
209220

210221
switchchannel.Protocol() {
211-
case"ssh":
222+
caseProtocolSSH:
212223
goa.sshServer.HandleConn(channel.NetConn())
213-
case"reconnecting-pty":
224+
caseProtocolReconnectingPTY:
214225
goa.handleReconnectingPTY(ctx,channel.Label(),channel.NetConn())
215-
case"dial":
226+
caseProtocolDial:
216227
goa.handleDial(ctx,channel.Label(),channel.NetConn())
217228
default:
218229
a.logger.Warn(ctx,"unhandled protocol from channel",
@@ -478,8 +489,8 @@ func (a *agent) handleReconnectingPTY(ctx context.Context, rawID string, conn ne
478489
a.logger.Warn(ctx,"start reconnecting pty command",slog.F("id",id))
479490
}
480491

481-
// Default to buffer64KB.
482-
circularBuffer,err:=circbuf.NewBuffer(64*1024)
492+
// Default to buffer64KiB.
493+
circularBuffer,err:=circbuf.NewBuffer(64<<10)
483494
iferr!=nil {
484495
a.logger.Warn(ctx,"create circular buffer",slog.Error(err))
485496
return

‎agent/agent_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,9 @@ func TestAgent(t *testing.T) {
172172
tempPath:=filepath.Join(os.TempDir(),"content.txt")
173173
content:="somethingnice"
174174
setupAgent(t, agent.Metadata{
175-
StartupScript:"echo"+content+" > "+tempPath,
175+
StartupScript:fmt.Sprintf("echo%s > %s",content,tempPath),
176176
},0)
177+
177178
vargotContentstring
178179
require.Eventually(t,func()bool {
179180
content,err:=os.ReadFile(tempPath)
@@ -202,6 +203,7 @@ func TestAgent(t *testing.T) {
202203
// it seems like it could be either.
203204
t.Skip("ConPTY appears to be inconsistent on Windows.")
204205
}
206+
205207
conn:=setupAgent(t, agent.Metadata{},0)
206208
id:=uuid.NewString()
207209
netConn,err:=conn.ReconnectingPTY(id,100,100)
@@ -228,6 +230,7 @@ func TestAgent(t *testing.T) {
228230
}
229231
}
230232
}
233+
231234
matchEchoCommand:=func(linestring)bool {
232235
returnstrings.Contains(line,"echo test")
233236
}

‎agent/conn.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type Conn struct {
3636
// be reconnected to via ID.
3737
func (c*Conn)ReconnectingPTY(idstring,height,widthuint16) (net.Conn,error) {
3838
channel,err:=c.CreateChannel(context.Background(),fmt.Sprintf("%s:%d:%d",id,height,width),&peer.ChannelOptions{
39-
Protocol:"reconnecting-pty",
39+
Protocol:ProtocolReconnectingPTY,
4040
})
4141
iferr!=nil {
4242
returnnil,xerrors.Errorf("pty: %w",err)
@@ -47,7 +47,7 @@ func (c *Conn) ReconnectingPTY(id string, height, width uint16) (net.Conn, error
4747
// SSH dials the built-in SSH server.
4848
func (c*Conn)SSH() (net.Conn,error) {
4949
channel,err:=c.CreateChannel(context.Background(),"ssh",&peer.ChannelOptions{
50-
Protocol:"ssh",
50+
Protocol:ProtocolSSH,
5151
})
5252
iferr!=nil {
5353
returnnil,xerrors.Errorf("dial: %w",err)
@@ -87,7 +87,7 @@ func (c *Conn) DialContext(ctx context.Context, network string, addr string) (ne
8787
}
8888

8989
channel,err:=c.CreateChannel(ctx,u.String(),&peer.ChannelOptions{
90-
Protocol:"dial",
90+
Protocol:ProtocolDial,
9191
Unordered:strings.HasPrefix(network,"udp"),
9292
})
9393
iferr!=nil {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp