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

Fix error when refreshing individual Ad Units and bidder responds slowly #981

Closed
wants to merge 2 commits into from

Conversation

ceresnam
Copy link

Type of change

  • Bugfix

Description of change

Bugfix for race condition.

Calling .reduce(flatten) in bidsBackAdUnit() and bidsBackAll() throws an exception when refreshing Ad unit.

That happens when some bidder takes long time to respond and second requestBids() (i.e. ad unit refresh) is called in meanwhile.

Here is a sequence diagram explaining in more detail why that happend. https://goo.gl/LPfkXc

@mkendall07
Copy link
Member

@ceresnam
Is there any observed bug that happens besides the thrown exception?

@protonate
Copy link
Collaborator

Here is a related issue: #919

@ceresnam
Copy link
Author

@protonate
Copy link
Collaborator

Also possibly related issue #985.

@protonate
Copy link
Collaborator

Thanks for the PR, if you would rebase onto current master it should resolve the build check failure, this was due to an unrelated PR.

@protonate
Copy link
Collaborator

I pulled this change into a new branch to resolve the build failure, see #989, closing.

@protonate protonate closed this Feb 13, 2017
@dmitriyshashkin
Copy link
Contributor

I was trying to figure out if this bug could have caused a discrepancy. So I've spent quite some time trying to reproduce this issue. And the only way I was able to do that is by calling pbjs.requestBids with an adUnit that has it's bids array empty. eg pbjs.requestBids({'adUnits': [{'code': 'a_code', 'bids': []}]}); or with an empty list of adUnits eg pbjs.requestBids({'adUnits': []});

If I reproduce the sequence described above, then even after the first auction is cleared and the second auction has started, and clearPlacements() has been called, the pbjs._bidsRequested still has a list of requests for the second auction. Yes, indeed they are for another ad unit, and they will be filtered-out inside bidsBackAdUnit, but what is left is not an empty array but an array with one element which is empty array. So the following code:
$$PREBID_GLOBAL$$._bidsRequested .map(request => request.bids .filter(adUnitsFilter.bind(this, $$PREBID_GLOBAL$$._adUnitCodes)) .filter(bid => bid.placementCode === adUnitCode))

produces something like this: [[]]

And while [].reduce(flatten) will cause an error, [[]].reduce(flatten) works just fine. So unless I'm missing something, the only way to reproduce the error is to have empty _bidsRequested array, which can only be achieved if you call requestBids with empty list of bids or empty list of adUnits.

So again if I'm not missing something, the issue above can not cause any discrepancy unless you pass erroneous parameters to requestBids.

And perhaps the proper way to adress this was to check the parameters that are passed to pbjs.requestBids

It would be great if someone could confirm or correct me.

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.

4 participants