Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing bufio.Scanner to bufio.Reader to support large message #3366

Merged
merged 1 commit into from
Aug 27, 2024

Conversation

CerberusQc
Copy link
Contributor

From the Issue #3343

As stated in the bufio Documentation, when using the bufio.Scanner, if the buffer exceed the max size of the token, the Scanner fail silently with an I/O error.

In the case of a container started with nerdctl, the main process using stdout/stderr hang forever when sending text bigger than 64kb (bufio.MaxScanTokenSize) without any newline character. (Discovered from a JSON string dumped in the logs). bufio documentation state to switch to a Reader instead when you do not have control over the size of the message.

Small test that is failing with the current master but working with this fix.

@apostasie recommend to check the other place in the code for the bufio.Scanner usage but I am not really a GO expert

pkg/logging/logging.go Outdated Show resolved Hide resolved
@apostasie
Copy link
Contributor

@CerberusQc you need to DCO your commit with git -S (and squash your commits here).

@apostasie
Copy link
Contributor

@apostasie recommend to check the other place in the code for the bufio.Scanner usage but I am not really a GO expert

That does not have to happen right now. Maybe if you can open a new issue, in the line of: "follow-up to #3343: review uses of bufio.Scanner", so that someone can pick that up later?

pkg/logging/logging.go Outdated Show resolved Hide resolved
@CerberusQc
Copy link
Contributor Author

@CerberusQc you need to DCO your commit with git -S (and squash your commits here).

@apostasie I will need help with this one, I have created a GPG key, signed the last 4 commits, when I tried to sign the first commit, it created a merge, now I can't squash correctly. I have no idea of what I am doing at this point and I am really not familiar with the process, sorry about this

@apostasie
Copy link
Contributor

apostasie commented Aug 26, 2024

@CerberusQc you need to DCO your commit with git -S (and squash your commits here).

@apostasie I will need help with this one, I have created a GPG key, signed the last 4 commits, when I tried to sign the first commit, it created a merge, now I can't squash correctly. I have no idea of what I am doing at this point and I am really not familiar with the process, sorry about this

No problem.

So, first, the DCO is unrelated to actual key signing.
What you MUST do for the DCO when commiting is git commit -s ...
That will add the DCO to your commit message (https://wiki.linuxfoundation.org/dco)
(apologies as I previously said -S - this one if for signing, which is nice, but not required).
If you want to do both (best), git commit -S -s -m "..."

About the rest - tis not you, tis git :D

You have 5 commits here, just soft reset them (commits are rolled-back, but your changes are preserved locally):

git reset --soft HEAD~5

And now you can start "fresh": just add then commit

git add pkg/logging/logging.go pkg/logging/logging_test.go

# Some basic sanity checks before committing
make lint
make lint-imports

# Change to whatever message suits you
git commit -S -s -m "fix log issue with large messages (bufio.Scanner > bufio.Reader)"

# Now force-push
git push -f

Future stuff - if you do need more modifications, just amend instead of adding new commits on top:

git add whatever
git commit --amend
git push -f

Does that help?

Addenda:

My personal religion forbids me from touching GPG keys without a hazmat suit. If you feel similarly, did you know you can sign with your ssh key instead?

gitconfig:

[user]
	name = xxx
	email = xxx
	signingkey = xxxx/.ssh/id_ed25519_sk.pub
[github]
	user = xxx

[commit]
	gpgsign = true

[gpg]
	format = ssh

@CerberusQc
Copy link
Contributor Author

@apostasie I think I have managed to make the basic squashing happen (feeling super noob here) I will check later for the unit tests to fix the stripping of newline

@apostasie
Copy link
Contributor

@apostasie I think I have managed to make the basic squashing happen (feeling super noob here) I will check later for the unit tests to fix the stripping of newline

Failure is visible on integration tests.

To reproduce locally, make sure your updated nerdctl binary is in your path, then:

go test ./cmd/nerdctl/ -run TestLogsOutStreamsSeparated

(TestLogsOutStreamsSeparated is one of the failing integration test)

@CerberusQc
Copy link
Contributor Author

@apostasie thank you for guiding me through this, I am really learning today and yes, I prefer SSH signing, I will switch to this in the future.

I have run the whole integration suite in container without any fail, let's see how the pipeline goes

@apostasie
Copy link
Contributor

@apostasie thank you for guiding me through this, I am really learning today and yes, I prefer SSH signing, I will switch to this in the future.

I have run the whole integration suite in container without any fail, let's see how the pipeline goes

That looks promising.
Good stuff here, @CerberusQc.

From the Issue containerd#3343

As stated in the bufio Documentation, when using the bufio.Scanner, if the buffer exceed the max size of the token, the Scanner fail silently with an I/O error.

In the case of a container started with nerdctl, the main process using stdout/stderr hang forever when sending text bigger than 64kb (bufio.MaxScanTokenSize) without any newline character. (Discovered from a JSON string dumped in the logs). bufio documentation state to switch to a Reader instead when you do not have control over the size of the message.

Small test that is failing with the current master but working with this fix.

@apostasie recommend to check the other place in the code for the bufio.Scanner usage but I am not really a GO expert

Will trim any \n if it is not EOF else, will send the data no matter and exit in case of error

Signed-off-by: Bastien Roy-Mazoyer <[email protected]>
@CerberusQc
Copy link
Contributor Author

@apostasie had some trouble making work the unit test and integration test on macOS but, looks good now, I decided to go with the second implementation plus a check on the length of the string, without it the unit tests does not pass for the TestLogsOutStreamsSeparated

@apostasie
Copy link
Contributor

LGTM

Tagging @AkihiroSuda @fahedouch for maintainers' review.

@AkihiroSuda AkihiroSuda added this to the v2.0.0 milestone Aug 27, 2024
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

Thanks

@AkihiroSuda AkihiroSuda merged commit 211a7a6 into containerd:main Aug 27, 2024
22 checks passed
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.

3 participants