1
1
package trafficgen
2
2
3
3
import (
4
- "bytes"
5
4
"context"
6
5
"encoding/json"
7
6
"io"
@@ -50,8 +49,8 @@ func (r *Runner) Run(ctx context.Context, _ string, logs io.Writer) error {
50
49
var (
51
50
agentID = r .cfg .AgentID
52
51
reconnect = uuid .New ()
53
- height uint16 = 65535
54
- width uint16 = 65535
52
+ height uint16 = 25
53
+ width uint16 = 80
55
54
tickInterval = r .cfg .TicksPerSecond
56
55
bytesPerTick = r .cfg .BytesPerSecond / r .cfg .TicksPerSecond
57
56
)
@@ -74,7 +73,8 @@ func (r *Runner) Run(ctx context.Context, _ string, logs io.Writer) error {
74
73
return xerrors .Errorf ("connect to workspace: %w" , err )
75
74
}
76
75
77
- defer func () {
76
+ go func () {
77
+ <- deadlineCtx .Done ()
78
78
logger .Debug (ctx , "close agent connection" , slog .F ("agent_id" , agentID ))
79
79
_ = conn .Close ()
80
80
}()
@@ -87,8 +87,8 @@ func (r *Runner) Run(ctx context.Context, _ string, logs io.Writer) error {
87
87
defer tick .Stop ()
88
88
89
89
// Now we begin writing random data to the pty.
90
- rch := make (chan error )
91
- wch := make (chan error )
90
+ rch := make (chan error , 1 )
91
+ wch := make (chan error , 1 )
92
92
93
93
go func () {
94
94
<- deadlineCtx .Done ()
@@ -141,14 +141,12 @@ func drainContext(ctx context.Context, src io.Reader, bufSize int64) error {
141
141
errCh := make (chan error , 1 )
142
142
done := make (chan struct {})
143
143
go func () {
144
- tmp := make ([]byte , bufSize )
145
- buf := bytes .NewBuffer (tmp )
146
144
for {
147
145
select {
148
146
case <- done :
149
147
return
150
148
default :
151
- _ , err := io .CopyN (buf , src , 1 )
149
+ _ , err := io .CopyN (io . Discard , src , 1 )
152
150
if ctx .Err () != nil {
153
151
return // context canceled while we were copying.
154
152
}
0 commit comments