Skip to content

Conversation

@GoldenSheep402
Copy link

In client.go

The origin code is:

	go func() {
		defer c.clientWaitGroup.Done()
		defer c.pipesWaitGroup.Done()
		defer close(linesCh)

		scanner := bufio.NewScanner(runner.Stdout())

		for scanner.Scan() {
			linesCh <- scanner.Text()
		}
		if scanner.Err() != nil {
			c.logger.Error("error encountered while scanning stdout", "error", scanner.Err())
		}
	}()

If runner.Stdout()is bigger than 64kb, it will cause [ERROR] plugin: error encountered while scanning stdout: error="bufio.Scanner: token too long"

A fixed version is:

	go func() {
		defer c.clientWaitGroup.Done()
		defer c.pipesWaitGroup.Done()
		defer close(linesCh)

		scanner := bufio.NewScanner(runner.Stdout())
		buf := make([]byte, c.config.ClientScanerBufferSize)
		scanner.Buffer(buf, c.config.ClientScanerBufferSize)

		for scanner.Scan() {
			linesCh <- scanner.Text()
		}
		if scanner.Err() != nil {
			c.logger.Error("error encountered while scanning stdout", "error", scanner.Err())
		}
	}()

The ClientScanerBufferSize is provided as a config item(default is 64KB), user can set it by themselves if their command will return a large output and avoid receiving a null result.

@hashicorp-cla-app
Copy link

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

Copy link

@sonamtenzin2 sonamtenzin2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add test cases for the failure scenario

// If this is 0, then the default of 64KB is used.
PluginLogBufferSize int

// ClientScanerBufferSize is the buffer size(bytes) to read from stderr for plugin log lines.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its more related to stdout than stderr


// ClientScanerBufferSize is the buffer size(bytes) to read from stderr for plugin log lines.
// If this is 0, then the default of 64KB is used.
ClientScanerBufferSize int

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo for Scanner

github.com/hashicorp/yamux v0.1.1 // indirect
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.10 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What caused this change ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants