Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Prevent overflows by increasing ring buffer size #47

Merged
merged 2 commits into from
May 29, 2016
Merged

Prevent overflows by increasing ring buffer size #47

merged 2 commits into from
May 29, 2016

Conversation

Byron
Copy link

@Byron Byron commented May 28, 2016

Via trial and error, I could verify that all google-api-rs
crates actually build if the ring-buffer is about 3 times
larger than before.

As the code is generated, some types are massive, and there
is more complexity than in hand-written code.

Increasing the buffer size should have no disadvantage, neither
to performance, nor on memory requirements.

PS: If merged, it would be nice to get a point-release soon to allow google-apis-rs to build again on stable. Thank you.


Related to Byron/google-apis-rs#148,
Fixes #33
Fixes serde-rs/serde#229
Maybe related to dermesser/yup-oauth2#16

Via trial and error, I could verify that all google-api-rs
crates actually build if the ring-buffer is about 3 times
larger than before.

As the code is generated, some types are massive, and there
is more complexity than in hand-written code.

Increasing the buffer size should have no disadvantage, neither
to performance, nor on memory requirements.
@Manishearth
Copy link

Does this belong in libsyntax itself? I'm not sure.

@Byron
Copy link
Author

Byron commented May 28, 2016

It does, and I just pushed the respective commit to my fork.
My plan was to build all google-apis locally to assure it works for everything, and then submit the PR to libsyntax too.

It seems, the most complex API, dfa-reporting, requires
an even higher value.

Reproduce this with
```
make dfareporting2d1-cli-cargo ARGS="build --no-default-features --features=with-syntex"
```
@erickt
Copy link

erickt commented May 29, 2016

Looks good to me, I'll include it in my current release, since libsyntax has broken everything again. Do you know why this is now required though? Was it a change in google-apis, or in syntex?

@erickt erickt merged commit f402aef into serde-deprecated:master May 29, 2016
@Byron
Copy link
Author

Byron commented May 29, 2016

Unfortunately I am nearly totally clueless. The only thing I know is that google-apis-rs didn't change the way they generate code. It seems to have started though when upgrading from serde 0.6 to 0.7. Maybe now it generates different types that require much more space when pretty-printed ?
Considering that magic factor had to increase nearly twenty-fold to accommodate the dfa-reporting API, it can probably be considered major.

Actually, the file generated by syntex has about 5000 empty lines right at the start, which might indicate something is quite wrong. The difference becomes striking when comparing the original linked above with the gist.

It might be that there is some sort of bug in the pretty-printer causing this, and this fix just cures the symptoms.

bors added a commit to rust-lang/rust that referenced this pull request May 29, 2016
Prevent overflows by increasing ring buffer size

Please note that this change is just done to prevent
issues as currently seen by syntex_syntax in future.
See serde-deprecated/syntex#47 for details.

As shown in serde-deprecated/syntex#33,
complex code can easily overflow the ring-buffer and
cause an assertion error.
@Byron
Copy link
Author

Byron commented May 29, 2016

I dug a little deeper, and here is what I found out. It might be interesting, if at some point we want to discover the true origin of the issue.

As far as I know, the issues started showing up when upgrading from serde 0.6.13 to something newer. It clear that between these versions, syntex changed from v0.28.0 to v0.29.0. Here is what changed between these versions.

Chances are that this bug is already fixed in libsyntax, as syntex_syntax appears to be a little bit behind when it comes to the pretty-printing code.

@indiv0
Copy link

indiv0 commented Jun 8, 2016

@erickt, @Byron I'm not sure about the root cause of the issue, but rusoto has gotten this issue as well (tracking at: rusoto/rusoto#248). In my testing, I re-ran a Travis CI build that built successfully earlier and it failed, so I can confirm that this issue is on syntex's/libsyntax's end.

Also, the merged fix didn't solve the bug for us, but that might be something else going wrong on our end (e.g. the build not using the new syntex version) as I haven't really taken a look at it yet.

@indiv0
Copy link

indiv0 commented Jun 8, 2016

@Byron actually could it not be fixed for rusoto because tripling the ring buffer isn't enough for rusoto? Cause our auto-generated code is several tens of thousands of lines IIRC.

If so, seems like we should find the root cause of the issue and fix that.

@Byron
Copy link
Author

Byron commented Jun 8, 2016

@indiv0 To me it seemed that factor depends on the size of the source code to be processed. The file that required this factor to be 55 was about 2.7MB in size.

I was naively thinking that this was sufficient for the next decades to come, and do agree that it would be time to fix the issue properly. It should be possible to replace the static buffer with a dynamically allocated one, even without knowing all the details of the implementation.

@indiv0
Copy link

indiv0 commented Jun 8, 2016

Would this be as straightforward as replacing the ring buffer with a Vec<Token> in libsyntax?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants