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

Prebid core: fix exception in requestBids introduced by #9106 #9194

Merged
merged 4 commits into from
Nov 3, 2022

Conversation

dgirardi
Copy link
Collaborator

@dgirardi dgirardi commented Nov 2, 2022

Type of change

  • Bugfix

Description of change

Fix a bug introduced by #9106: if a module such as userId needs to delay the auction (auctionDelay > 0), it can cause hooks to run out of order and error out.

Fixes #9191

@dgirardi
Copy link
Collaborator Author

dgirardi commented Nov 2, 2022

@ChrisHuie and reviewers, please leave this open until it's time to release, I'll see if I can update this to be a proper fix by then, otherwise please merge and release.

Pr updated with an actual fix.

@dgirardi dgirardi changed the title Revert "Prebid core: return a promise from requestBids (#9106)" Prebid core: fix exception in requestBids introduced by #9106 Nov 2, 2022
Copy link
Collaborator

@muuki88 muuki88 left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this so fast @dgirardi 🤗

Comment on lines +646 to +648
req.defer = defer({promiseFactory: (r) => new Promise(r)})
delegate.call(this, req);
return req.defer.promise;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe a few comments why this is necessary would be helpful.

As someone only looking at bid adapters mostly the fun-hook framework and the custom promise implementation this code is non-obivous why it's there.

Copy link
Collaborator Author

@dgirardi dgirardi Nov 3, 2022

Choose a reason for hiding this comment

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

If you're asking about the reason for fun-hooks or the custom promise:

  • fun-hooks is basically a plugin system (to the author: sorry if I'm oversimplifying this). if we have 5 modules that may be loaded in a random combination and order, and all plug into the same code path, fun-hook solves the problem of orchestrating those. I can't answer why we are using that over something else.
  • the custom promise - A version of Promise that runs callbacks synchronously when it can - came about because of this discussion.

As for this code specifically, I tried clarifying it in the comments - it boils down to idiosyncrasies of fun-hooks.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for the clarification 🤗

@@ -1665,7 +1677,7 @@ describe('Unit: Prebid Module', function () {
sinon.assert.match(bids[bid.adUnitCode].bids[0], bid)
done();
});
completeAuction([bid]);
setTimeout(() => completeAuction([bid]));
Copy link
Collaborator

Choose a reason for hiding this comment

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

also a small comment here why wrapping in setTimeout is required here

@@ -622,15 +623,15 @@ $$PREBID_GLOBAL$$.removeAdUnit = function (adUnitCode) {
* @alias module:pbjs.requestBids
*/
$$PREBID_GLOBAL$$.requestBids = (function() {
const delegate = hook('sync', function ({ bidsBackHandler, timeout, adUnits, adUnitCodes, labels, auctionId, ttlBuffer, ortb2, metrics } = {}) {
const delegate = hook('async', function ({ bidsBackHandler, timeout, adUnits, adUnitCodes, labels, auctionId, ttlBuffer, ortb2, metrics, defer } = {}) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

When I discovered the issue a little more comments would have helped what the intention of this delegate method was or what it is supposed to do.

@ChrisHuie ChrisHuie self-requested a review November 3, 2022 11:11
@ChrisHuie ChrisHuie self-assigned this Nov 3, 2022
@ChrisHuie ChrisHuie merged commit bf85447 into prebid:master Nov 3, 2022
dgirardi added a commit to dgirardi/Prebid.js that referenced this pull request Nov 3, 2022
…prebid#9194)

* Revert "Prebid core: return a promise from `requestBids` (prebid#9106)"

This reverts commit 64aff9b.

* Revert "Revert "Prebid core: return a promise from `requestBids` (prebid#9106)""

This reverts commit bf5ee30.

* Prebid core: fix exception in `requestBids` introduced by prebid#9106

* Add comments
patmmccann pushed a commit that referenced this pull request Nov 3, 2022
… (#9200)

* Revert "Prebid core: return a promise from `requestBids` (#9106)"

This reverts commit 64aff9b.

* Revert "Revert "Prebid core: return a promise from `requestBids` (#9106)""

This reverts commit bf5ee30.

* Prebid core: fix exception in `requestBids` introduced by #9106

* Add comments
JacobKlein26 pushed a commit to nextmillenniummedia/Prebid.js that referenced this pull request Feb 9, 2023
…prebid#9194)

* Revert "Prebid core: return a promise from `requestBids` (prebid#9106)"

This reverts commit 64aff9b.

* Revert "Revert "Prebid core: return a promise from `requestBids` (prebid#9106)""

This reverts commit bf5ee30.

* Prebid core: fix exception in `requestBids` introduced by prebid#9106

* Add comments
jorgeluisrocha pushed a commit to jwplayer/Prebid.js that referenced this pull request May 23, 2023
…prebid#9194)

* Revert "Prebid core: return a promise from `requestBids` (prebid#9106)"

This reverts commit 64aff9b.

* Revert "Revert "Prebid core: return a promise from `requestBids` (prebid#9106)""

This reverts commit bf5ee30.

* Prebid core: fix exception in `requestBids` introduced by prebid#9106

* Add comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

return a promise from requestBids causes issues along with criteoId
4 participants