Skip to content

Commit

Permalink
Fix process output scan buffer initialization and resizing (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentaTomas committed Apr 11, 2024
2 parents e7e7662 + 99e69a9 commit c34b6cc
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/envd/internal/process/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ type Service struct {
processes *Manager
}

const maxScanCapacity = 64 * 1024 * 1024 // 64MB
const (
startScanCapacity = 2 * 1024 // 2KB
maxScanCapacity = 32 * 1024 * 1024 // 32MB
)

func NewService(logger *zap.SugaredLogger, env *env.EnvConfig, clock *clock.Service) *Service {
return &Service{
Expand Down Expand Up @@ -58,10 +61,10 @@ func (s *Service) scanRunCmdOut(pipe io.Reader, t output.OutType, process *Proce
// Pipe should be automatically closed when the process exits -> this should EOF the scanner.
scanner := bufio.NewScanner(pipe)

buf := make([]byte, 0, maxScanCapacity)
buf := make([]byte, 0, startScanCapacity)
scanner.Buffer(buf, maxScanCapacity)

// The default max buffer size is 64k - we are increasing this to 64MB.
// The default max buffer size is 64k - we are increasing this to default 2KB and up to 32MB.
for scanner.Scan() {
line := scanner.Text()

Expand Down

0 comments on commit c34b6cc

Please sign in to comment.