-
Notifications
You must be signed in to change notification settings - Fork 774
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
Panics happen when left with zero length []Imp #1462
Conversation
adapters/info.go
Outdated
|
||
if len(request.Imp) == 0 { | ||
return nil, []error{BadInput("Empty Imp array in bid request")} | ||
} |
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.
The true branch of this if statement is unreachable because request validation in endpoints/openrtb2/*auction.go
discards requests with empty []Imp
. Nevertheless, I believe having it in place makes for a more robust function at O(1) cost. What do you think?
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.
This info
bidder is a special case. (.. and kind of gross? when wouldn't we have an info aware bidder? why not just build this into the core?.. all questions for another time).
If this code is unreachable, I vote to remove it.
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.
Corrected it so we can exit with an error without the need of this unreachable code. Let me know what you think of the new logic.
Removed
adapters/info.go
Outdated
|
||
if len(request.Imp) == 0 { | ||
return nil, []error{BadInput("Empty Imp array in bid request")} | ||
} |
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.
This info
bidder is a special case. (.. and kind of gross? when wouldn't we have an info aware bidder? why not just build this into the core?.. all questions for another time).
If this code is unreachable, I vote to remove it.
adapters/info.go
Outdated
@@ -57,6 +62,11 @@ func (i *InfoAwareBidder) MakeRequests(request *openrtb.BidRequest, reqInfo *Ext | |||
// see if any imps need to be removed, and another to do the removing if necessary. | |||
numToFilter, errs := i.pruneImps(request.Imp, allowedMediaTypes) | |||
if numToFilter != 0 { | |||
// If no valid imps left, avoid expensive filtering process |
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.
Can you please reword this comment? It's not avoiding filtering, but rather exiting early, right? We weren't generating an error before this PR.
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
adapters/info_test.go
Outdated
@@ -56,6 +58,7 @@ func TestSiteNotSupported(t *testing.T) { | |||
} | |||
|
|||
func TestImpFiltering(t *testing.T) { | |||
// Set up |
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.
Nitpick: The comments don't seem helpful here. Please consider removing.
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.
removed
adapters/info_test.go
Outdated
Video: &openrtb.Video{}, | ||
|
||
// Define test cases | ||
type testOut struct { |
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.
Does this really have to be a separate struct? Why not add expectedErrors
and expectedImps
to the testCases
struct?
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.
Modified
adapters/info_test.go
Outdated
} | ||
|
||
// Extra MakeRequests() call check: our mockBidder returns an adapter request for every imp | ||
assert.Equal(t, test.expectedImpLen, len(actualAdapterRequests), "Test failed. Incorrect lenght of filtered imps: %s", test.description) |
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.
@SyntaxNode let me know if you agree with this "extra" check. Strictly speaking, we don't need it. Do you want me to remove it?
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 think it's fine to keep. There's a few test cases with expected imps. Consider using assert.Len
though.
adapters/info.go
Outdated
|
||
// If all imps in bid request come with unsupported media types, exit | ||
if numToFilter == len(request.Imp) { | ||
return nil, append(errs, BadInput("Bid request didn't contain media types supported by bidder")) |
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.
Nitpick: supported by the bidder
adapters/info_test.go
Outdated
} | ||
|
||
// Extra MakeRequests() call check: our mockBidder returns an adapter request for every imp | ||
assert.Equal(t, test.expectedImpLen, len(actualAdapterRequests), "Test failed. Incorrect lenght of filtered imps: %s", test.description) |
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 think it's fine to keep. There's a few test cases with expected imps. Consider using assert.Len
though.
Sometimes an
openrtb.BidRequest
's[]Imp
slice gets completely emptied after filtering out imps with wrong media types inadapters/info.go
as defined in the bidder'sstatic/bidder-info/*.yaml
file. This pull request modifies theInfoAwareBidder
's filtering process to not send requests with an emptyImp
slice to any adapter to avoid panics in case the bidder's adapter de-references an slice element.Test request:
Test request output before this PR's changes:
Client
Server
After this changes
Client
Server