fix: handle SSH bridge write errors in poller
Add error checking to all three write calls in bridge.go. A write failure now terminates that goroutine's copy loop and triggers cancel, which lets the other goroutines clean up naturally. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
|
"log/slog"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -40,7 +41,10 @@ func bridge(ctx context.Context, cancel context.CancelFunc, ws *websocket.Conn,
|
|||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
stdin.Write(data)
|
if _, err := stdin.Write(data); err != nil {
|
||||||
|
slog.Debug("SSH stdin write failed", "error", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -54,7 +58,10 @@ func bridge(ctx context.Context, cancel context.CancelFunc, ws *websocket.Conn,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
atomic.StoreInt64(lastActive, time.Now().UnixNano())
|
atomic.StoreInt64(lastActive, time.Now().UnixNano())
|
||||||
ws.Write(ctx, websocket.MessageBinary, buf[:n])
|
if err := ws.Write(ctx, websocket.MessageBinary, buf[:n]); err != nil {
|
||||||
|
slog.Debug("SSH→WebSocket write failed", "error", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -67,7 +74,10 @@ func bridge(ctx context.Context, cancel context.CancelFunc, ws *websocket.Conn,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ws.Write(ctx, websocket.MessageBinary, buf[:n])
|
if err := ws.Write(ctx, websocket.MessageBinary, buf[:n]); err != nil {
|
||||||
|
slog.Debug("SSH→WebSocket write failed", "error", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user