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

Commitb30bc20

Browse files
committed
Remove err from wait callback
We do not really do anything with it other than just return it, and ifwe do need to do something with it we can just do it on the return from`waitForStateOrContext`, we probably would not need to use it behind themutex.Also we should check the state outside, not err, since there istechnically no guarantee an error is set on a state change (although inpractice for close/done there always is, maybe this should be enforcedin some way).
1 parent34c5c1a commitb30bc20

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

‎agent/reconnectingpty/buffered.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,19 +179,19 @@ func (rpty *bufferedReconnectingPTY) Attach(ctx context.Context, connID string,
179179
defercancel()
180180

181181
// Once we are ready, attach the active connection while we hold the mutex.
182-
_,err:=rpty.state.waitForStateOrContext(ctx,StateReady,func(stateState,errerror)error {
182+
state,err:=rpty.state.waitForStateOrContext(ctx,StateReady,func(stateState)error {
183183
// Write any previously stored data for the TTY. Since the command might be
184184
// short-lived and have already exited, make sure we always at least output
185185
// the buffer before returning.
186186
prevBuf:=slices.Clone(rpty.circularBuffer.Bytes())
187-
_,writeErr:=conn.Write(prevBuf)
188-
ifwriteErr!=nil {
187+
_,err:=conn.Write(prevBuf)
188+
iferr!=nil {
189189
rpty.metrics.WithLabelValues("write").Add(1)
190-
returnxerrors.Errorf("write buffer to conn: %w",writeErr)
190+
returnxerrors.Errorf("write buffer to conn: %w",err)
191191
}
192192

193193
ifstate!=StateReady {
194-
returnerr
194+
returnnil
195195
}
196196

197197
goheartbeat(ctx,rpty.timer,rpty.timeout)
@@ -209,7 +209,7 @@ func (rpty *bufferedReconnectingPTY) Attach(ctx context.Context, connID string,
209209

210210
returnnil
211211
})
212-
iferr!=nil {
212+
ifstate!=StateReady {
213213
returnxerrors.Errorf("reconnecting pty ready wait: %w",err)
214214
}
215215

‎agent/reconnectingpty/reconnectingpty.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ func (s *ptyState) waitForState(state State) (State, error) {
168168

169169
// waitForStateOrContext blocks until the state or a greater one is reached or
170170
// the provided context ends. If fn is non-nil it will be ran while the lock is
171-
// held unless the context ends, and fn's error will replace
172-
// waitForStateOrContext's error.
173-
func (s*ptyState)waitForStateOrContext(ctx context.Context,stateState,fnfunc(stateState,errerror)error) (State,error) {
171+
// held unless the context ends. If fn returns an error then fn's error will
172+
//replacewaitForStateOrContext's error.
173+
func (s*ptyState)waitForStateOrContext(ctx context.Context,stateState,fnfunc(stateState)error) (State,error) {
174174
nevermind:=make(chanstruct{})
175175
deferclose(nevermind)
176176
gofunc() {
@@ -191,7 +191,10 @@ func (s *ptyState) waitForStateOrContext(ctx context.Context, state State, fn fu
191191
returns.state,ctx.Err()
192192
}
193193
iffn!=nil {
194-
returns.state,fn(s.state,s.error)
194+
err:=fn(s.state)
195+
iferr!=nil {
196+
returns.state,err
197+
}
195198
}
196199
returns.state,s.error
197200
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp