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

cap max msg size to min(max_int, max_uint32) #1598

Merged
merged 4 commits into from
Oct 24, 2017
Merged

Conversation

lyuxuan
Copy link
Contributor

@lyuxuan lyuxuan commented Oct 19, 2017

No description provided.

@lyuxuan lyuxuan assigned dfawley and unassigned dfawley Oct 19, 2017

// Cap the max size to the max int of current machine due to limit of
// slice length.
res = min(res, newInt(int((^uint(0) >> 1))))
Copy link
Member

Choose a reason for hiding this comment

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

For clarity, how about this:

maxInt := int(^uint(0) >> 1) // the maximum signed integer value on this system
res = min(res, &maxInt)

(Note that your version has an extra pair of parentheses which is hard to see because of all the nesting.)

Why does min() take pointers? That just complicates things further. maxInt could and should be a const instead.

How about make min() and get*MaxSize() take and return ints, and deal with pointers only where you call them:

c.maxSendMessageSize = newInt(getMaxSize(*mc.MaxReqSize, *c.maxSendMessageSize, defaultClientMaxSendMessageSize))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that we should make maxInt const.

getMaxSize was created to handle pointers to avoid dealing with nil condition in caller. It hides the complexity from caller. And min() is just to keep logic simple as we don't need to convert int to *int when returned from it. Probably we should rename these two functions to avoid future confusions (like the input and output are all pointer type)? They are created very specifically for service config and not intended for general usage.

Copy link
Member

Choose a reason for hiding this comment

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

How about this:

  • Change callInfo.max*MessageSize to non-pointer types, since they must always be set. This removes some paranoid checking
  • Change min() to accept and return int instead of *int
  • Change get[Raw]MaxSize to return ints instead of *ints

Is that possible? I think this would make things simpler and keep getMaxSize able to handle *int inputs.

Copy link
Contributor Author

@lyuxuan lyuxuan Oct 20, 2017

Choose a reason for hiding this comment

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

I don't think we can. callInfo.max*MessageSize is a pointer type because it will be used to receive the value set by user API MaxCall*MsgSize when we configure the call. And we need nil value to indicate that user doesn't set it. And then during invoke, we will reassign its value based on service config value, its current value and default value.

Copy link
Member

Choose a reason for hiding this comment

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

OK.. well let's just make min deal with ints then? We can deal with the pointers where it's called. Then we can have a const for maxInt and use it without creating memory.

Let's make sure we add some comments on these CallOptions/ServerOptions that specify the maximum effective value is MaxUint32 due to protocol limitations.

@dfawley dfawley assigned lyuxuan and dfawley and unassigned lyuxuan and dfawley Oct 20, 2017
@lyuxuan
Copy link
Contributor Author

lyuxuan commented Oct 21, 2017

fix #1590

@lyuxuan lyuxuan merged commit 5856538 into grpc:master Oct 24, 2017
dfawley added a commit to dfawley/grpc-go that referenced this pull request Oct 25, 2017
@dfawley
Copy link
Member

dfawley commented Oct 25, 2017

Rolled back by #1619

dfawley added a commit that referenced this pull request Oct 25, 2017
@menghanl menghanl added this to the 1.8 Release milestone Nov 7, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants