Skip to content

Commit

Permalink
Merge pull request #232 from ipfs-force-community/fix/dtynn/use_bufio…
Browse files Browse the repository at this point in the history
…_reader_instead_of_scanner

fix(vsmgr): use bufio.Reader to avoid bufio.Scanner: token too long
  • Loading branch information
diwufeiwen authored Jun 13, 2022
2 parents 3c649ed + 44b15a4 commit 658aea2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,20 @@ var processorWdPostCmd = &cli.Command{

plog.Info("ready")

in := bufio.NewScanner(os.Stdin)
in := bufio.NewReaderSize(os.Stdin, 1<<20)
out := bufio.NewWriter(os.Stdout)
var outMu = &sync.Mutex{}

var readErr error
for {
if !in.Scan() {
b, err := in.ReadBytes('\n')
if err != nil {
readErr = err
break
}

var req ext.Request
b := in.Bytes()
err := json.Unmarshal(b, &req)
err = json.Unmarshal(b, &req)
if err != nil {
plog.Warnf("decode incoming request: %s", err)
continue
Expand All @@ -70,8 +72,8 @@ var processorWdPostCmd = &cli.Command{
}()
}

if err := in.Err(); err != nil {
plog.Warnf("stdin broken: %s", err)
if readErr != nil {
plog.Warnf("stdin broken: %s", readErr)
}

return nil
Expand Down
18 changes: 12 additions & 6 deletions venus-sector-manager/modules/impl/prover/ext/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,18 @@ func (sp *subProcessor) handleResponse(ctx context.Context) {
splog.Info("response loop start")
defer splog.Info("response loop stop")

scanner := bufio.NewScanner(sp.stdout)
reader := bufio.NewReaderSize(sp.stdout, 1<<20)
var readErr error

for {
b, err := reader.ReadBytes('\n')
if err != nil {
readErr = err
break
}

for scanner.Scan() {
var resp Response
b := scanner.Bytes()
err := json.Unmarshal(b, &resp)
err = json.Unmarshal(b, &resp)
if err != nil {
splog.Warnf("decode response from stdout of sub: %s", err)
continue
Expand All @@ -144,8 +150,8 @@ func (sp *subProcessor) handleResponse(ctx context.Context) {
}
}

if err := scanner.Err(); err != nil {
splog.Warnf("sub stdout scanner error: %s", err)
if readErr != nil {
splog.Warnf("sub stdout scanner error: %s", readErr)
}

}
Expand Down

0 comments on commit 658aea2

Please sign in to comment.