Skip to content

Commit 72ad811

Browse files
committed
address spike's comments
1 parent 5c24d07 commit 72ad811

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

enterprise/wsproxy/wsproxysdk/wsproxysdk.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ func (c *Client) DialCoordinator(ctx context.Context) (agpl.MultiAgentConn, erro
460460
rma := remoteMultiAgentHandler{
461461
sdk: c,
462462
nc: nc,
463+
cancel: cancel,
463464
legacyAgentCache: map[uuid.UUID]bool{},
464465
}
465466

@@ -485,6 +486,7 @@ func (c *Client) DialCoordinator(ctx context.Context) (agpl.MultiAgentConn, erro
485486
err := dec.Decode(&msg)
486487
if err != nil {
487488
if xerrors.Is(err, io.EOF) {
489+
c.SDKClient.Logger().Info(ctx, "multiagent connection severed", slog.Error(err))
488490
return
489491
}
490492

@@ -504,8 +506,9 @@ func (c *Client) DialCoordinator(ctx context.Context) (agpl.MultiAgentConn, erro
504506
}
505507

506508
type remoteMultiAgentHandler struct {
507-
sdk *Client
508-
nc net.Conn
509+
sdk *Client
510+
nc net.Conn
511+
cancel func()
509512

510513
legacyMu sync.RWMutex
511514
legacyAgentCache map[uuid.UUID]bool
@@ -522,10 +525,12 @@ func (a *remoteMultiAgentHandler) writeJSON(v interface{}) error {
522525
// Node updates are tiny, so even the dinkiest connection can handle them if it's not hung.
523526
err = a.nc.SetWriteDeadline(time.Now().Add(agpl.WriteTimeout))
524527
if err != nil {
528+
a.cancel()
525529
return xerrors.Errorf("set write deadline: %w", err)
526530
}
527531
_, err = a.nc.Write(data)
528532
if err != nil {
533+
a.cancel()
529534
return xerrors.Errorf("write message: %w", err)
530535
}
531536

@@ -536,6 +541,7 @@ func (a *remoteMultiAgentHandler) writeJSON(v interface{}) error {
536541
// our successful write, it is important that we reset the deadline before it fires.
537542
err = a.nc.SetWriteDeadline(time.Time{})
538543
if err != nil {
544+
a.cancel()
539545
return xerrors.Errorf("clear write deadline: %w", err)
540546
}
541547

0 commit comments

Comments
 (0)