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

Richaudience: Shared memory fix #2710

Merged
merged 5 commits into from
May 1, 2023
Merged

Conversation

VeronikaSolovei9
Copy link
Contributor

Adapters receive a shallow copy of a request In MakeBids. It means this request has shared pointer values: site, app and other pointer structures are shared between all adapters in request. In order to modify pointer structures you need to create own copy of it and set it back to request.
The reason why previous unit tests didn't show it is because imp.tagid was empty and result app/site.keywords didn't change.
Please review. @richaudience

@@ -52,10 +52,18 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapte
}

if request.App != nil {

Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: Please remove the leading white space here and for the Site check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}

b := &adapters.TypedBid{
Bid: &seatBid.Bid[i],
Bid: &bidResp.SeatBid[j].Bid[i],
BidType: bidType,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are these changes necessary for the bid processing loop? I'm not seeing the issue with the original code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are no issues with this. We discussed this with the team and decided this is the right way to do this, similar to how we access Bid by index. I can revert it back.

Copy link
Contributor

@SyntaxNode SyntaxNode Apr 24, 2023

Choose a reason for hiding this comment

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

I would recommend to revert this change. There's nothing wrong with the original code and this change is unrelated to the memory corruption.

Arguably, seatBid.Bid[i] is preferred over bidResp.SeatBid[j].Bid[i].

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted

Copy link
Contributor

@SyntaxNode SyntaxNode left a comment

Choose a reason for hiding this comment

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

request.Device.IP also has a shared memory violation issue. @guscarreon these lines of code are covered by tests, why did the shared memory assertions pass here?

@bsardo
Copy link
Collaborator

bsardo commented Apr 24, 2023

request.Device.IP also has a shared memory violation issue. @guscarreon these lines of code are covered by tests, why did the shared memory assertions pass here?

This does not appear to be an infrastructure issue; it's the tests. Let's update the mockBidRequest objects in all of the JSON tests by removing the following line "keywords": "tagid=", in the site and app objects wherever it is present. This line was masking the shared memory error since the keywords value computed by the adapter MakeRequests function was always the same as what was in the original bid request.

We should make sure that similar adjustments are made to the tests to detect shared memory issues with the device object.

@bsardo bsardo self-assigned this Apr 24, 2023
@VeronikaSolovei9
Copy link
Contributor Author

request.Device.IP also has a shared memory violation issue. @guscarreon these lines of code are covered by tests, why did the shared memory assertions pass here?

Good catch about Device.Ip!
The reason why tests didn't catch it is because all tests have input Device.ip set to "ip": "11.222.33.44". To reproduce this problem input Device.ip should be different from "11.222.33.44". Similar to site|app.keywords

bsardo
bsardo previously approved these changes Apr 24, 2023
Copy link
Collaborator

@bsardo bsardo left a comment

Choose a reason for hiding this comment

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

LGTM

@VeronikaSolovei9
Copy link
Contributor Author

@richaudience Can you please confirm (or not) you always expect only 1 impression per request?
With recently added changes if request has more than one imp, site|app.keywords will be overwritten with the value from the last imp in array. In addition to this raiExt.Test per imp can be different which leads to inconsistency in data that should be saved in request.Device.IP.
Current solution in this PR will work correctly and expected (in my understanding) if there is ONLY one impression in request.
Good catch @guscarreon

@bsardo bsardo self-requested a review April 27, 2023 17:27
Copy link
Contributor

@guscarreon guscarreon left a comment

Choose a reason for hiding this comment

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

LGTM

@hhhjort hhhjort merged commit a2fadfb into master May 1, 2023
blueseasx pushed a commit to blueseasx/prebid-server that referenced this pull request Jun 2, 2023
* Shared memory fix

* Minor reference usage fix

* Removed empty lines

* Code review feedback addressed

* Added nil check for req.device
@SyntaxNode SyntaxNode deleted the shared_mem_fix_richaudience branch August 28, 2023 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants