forked from wrenn/wrenn
Fix file browser crash on non-regular files and connection leaks
- envd: reject non-regular files (devices, pipes, sockets) in GetFiles to prevent infinite reads from /dev/zero, /dev/urandom etc. - host agent: add context cancellation check in ReadFileStream loop with proper Connect error codes - frontend: abort in-flight file reads on file switch, directory navigation, and component teardown via AbortController - frontend: guard against abort errors surfacing in UI, use try/finally for fileLoading state
This commit is contained in:
@ -516,6 +516,16 @@ func (s *Server) ReadFileStream(
|
||||
// Stream file content in 64KB chunks.
|
||||
buf := make([]byte, 64*1024)
|
||||
for {
|
||||
// Bail out early if the client disconnected or the context was cancelled.
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
if ctx.Err() == context.DeadlineExceeded {
|
||||
return connect.NewError(connect.CodeDeadlineExceeded, ctx.Err())
|
||||
}
|
||||
return connect.NewError(connect.CodeCanceled, ctx.Err())
|
||||
default:
|
||||
}
|
||||
|
||||
n, err := resp.Body.Read(buf)
|
||||
if n > 0 {
|
||||
chunk := make([]byte, n)
|
||||
|
||||
Reference in New Issue
Block a user