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

Fix #5299 and remove uncesssary unbounded buffer #5696

Merged
merged 3 commits into from
Dec 1, 2021

Conversation

Ericson2314
Copy link
Member

@Ericson2314 Ericson2314 commented Nov 30, 2021

See each commit message for details

Ericson2314 and others added 3 commits November 30, 2021 21:55
No more buffering in string.
This doesn't fix the bug, but makes the code less difficult to read.
Also improve the comments, now that it is clear what part is needed in
each code path.
No matter what, we need to resize the buffer to not have any scratch
space after we do the `read`. In the end of file case, `got` will be 0
from it's initial value.

Before, we forgot to resize in the EOF case with the break. Yes, we know
we didn't recieve any data in that case, but we still have the scatch
space to undo.

Co-Authored-By: Will Fancher <Will.Fancher@Obsidian.Systems>
Copy link
Member

@thufschmitt thufschmitt left a comment

Choose a reason for hiding this comment

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

Thanks!

It does indeed fix #5299 and makes things nicer to read in the end 👍

@edolstra edolstra merged commit fb662e0 into NixOS:master Dec 1, 2021
Copy link
Member

@dtzWill dtzWill left a comment

Choose a reason for hiding this comment

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

See review comments for some minor touchups to the larger of introduced comments.

Also in interest of not just nitpicking and helping craft this instead here's one possible alternative (attempting to keep/use your language) which maybe is not better:

Pass through the NAR unmodified into saved, but use parseDump to parse it anyway so we aren't sending arbitrary data unwittingly, and so that we only consume the NAR off of from and not past it.
(We don't trust addToStoreFromDump to not eagerly consume the entire stream it's given, past the length of the NAR.)

(personally I have no idea why addtoStoreFromDump is mentioned here, but leaving it in spirit of Chesterson's fence, and I'm very much not suggesting it's not there for a good reason 😄).

Whatever you think is best, hope this helps! 😄.


Tried to not too intrusively clarify we're letting parseDump drive the amount consumed (TeeSource only writing to saved what is read from it in parseDump, since that seems to be the point of this)--behavior that wasn't obvious to me but I'm not super familiar with the Source/Sink bits we've got, but IDK. Mostly "parse it" is not obviously "parse and read a limited amount (one object)" as that's not normally strictly speaking what I think of as the role of a parser. But that is clearly what's expected, for example, in the else side of this and likely elsewhere so 🤷.

Honestly maybe what you have with your selection of the suggested fixups is best! 👍.


auto dumpSource = sinkToSource([&](Sink & saved) {
if (method == FileIngestionMethod::Recursive) {
/* We parse the NAR dump through into `saved` unmodified,
Copy link
Member

Choose a reason for hiding this comment

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

We parse the NAR dump

was "We pass the NAR dump" meant instead?

I mean yes we parse it too, but it seems that's the part we're explaining is why we're parsing despite passing it through unmodified. Wouldn't bring it up but there are few other fixups...

/* We parse the NAR dump through into `saved` unmodified,
so why all this extra work? We still parse the NAR so
that we aren't sending arbitrary data to `saved`
unwittingly`, and we know when the NAR ends so we don't
Copy link
Member

Choose a reason for hiding this comment

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

unwittingly`

(Seems like stray backtick?)

and we know when the NAR

This was confusing to me on first read, I want to suggest "and so that we know when the NAR". But then that's a lot of "so"s in a row. Writing is hard haha.

consume the rest of `from` and can't parse another
command. (We don't trust `addToStoreFromDump` to not
eagerly consume the entire stream it's given, past the
length of the Nar. */
Copy link
Member

Choose a reason for hiding this comment

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

Nar

Nar -> NAR? (for consistency's sake?)

Also, the paren here is unmatched/missing end paren.

@Ericson2314 Ericson2314 deleted the fix-5299 branch December 2, 2021 09:58
@Ericson2314
Copy link
Member Author

@dtzWill Would you want to just make another PR rewriting the comment as you fit? I would be happy to review it!

@Ma27
Copy link
Member

Ma27 commented Dec 7, 2021

@edolstra @Ericson2314 as shown in #5740, this actually causes noticeable, yet weird problems.
Would you mind backporting this and perhaps even releasing a new Nix 2.4? :)

@Ericson2314
Copy link
Member Author

N.B. backport PR is already up at #5721

edolstra added a commit that referenced this pull request Dec 7, 2021
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.

5 participants