-
Notifications
You must be signed in to change notification settings - Fork 352
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 issue #1883, MultipartMixed grows cache indefinitely #1887
Conversation
… exploding the cache.
d41d2ee
to
103c685
Compare
103c685
to
f0a6531
Compare
/// <returns></returns> | ||
private static string RemoveBoundary(string contentTypeName) | ||
{ | ||
if (contentTypeName.StartsWith("multipart", StringComparison.OrdinalIgnoreCase)) |
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.
json batch also has the "mulitpart"? #Resolved
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.
No; json uses application/json, which does not have a boundary parameter.
The boundary issue is specific to multipart/mixed, which uses a "boundary" mime type parameter to distinguish requests within the multipart/mixed batch payload.
In reply to: 492449803 [](ancestors = 492449803)
{ | ||
// our formatters don't care about parameters for multipart, so just strip them all out for simplicity | ||
int parameter = contentTypeName.IndexOf(';'); | ||
if (parameter > 0) |
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 assume there will be only 1 ';' in the string, so rather than index and then substring, can we do in 1 pass? may be by using a stringbuilder
Issues
This pull request fixes issue #1883
Description
The process of matching a formatter to a media type can be expensive, so we cache the results of a lookup in our MediaTypeCache. Unfortunately, since the key for this cache is the content type, each new content type is a separate entry in the cache.
The multipart/mixed mime type, used for batch, has a required boundary parameter, expressed as part of the media type in the content-type header, which may be set to any random value.
Some clients have fixed values for these, but it's not uncommon to use a guid.
Because a guid makes each content-type unique, the cache size grows unbounded.
The boundary isn't needed to look up the formatter, so can safely be removed from the cache lookup key.
Also fixed apparent misunderstanding in the code of the size parameter passed to the concurrent dictionary constructor. It is not a max size, but an initial size for the cache.
Checklist (Uncheck if it is not completed)