-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Conversation
service_config.go
Outdated
|
||
// 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)))) |
There was a problem hiding this comment.
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))
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 returnint
instead of*int
- Change
get[Raw]MaxSize
to returnint
s instead of*int
s
Is that possible? I think this would make things simpler and keep getMaxSize
able to handle *int
inputs.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 int
s 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.
fix #1590 |
This reverts commit 5856538.
Rolled back by #1619 |
No description provided.