bidmanager.executeCallback potential bug breaks and prevents bidsBackHandler to be called
We use an infinite scroll where we add adunits as the user scrolls. The bug prevents bidsBackHandler from running on the second and subsequents requests when we add them sequentially.
I have created two examples, one where we can see the bug and the other using a prebid compiled with a simple change that fixes it. The example takes as base http://prebid.github.io/dev-docs/examples/adunit-refresh.html and it's adapted to simulate what we do in our infinite scroll, meaning that we add adUnits as they appear in the page not from the beginning like the example does. The page loads creating adUnits, then we add them to prebid and call requestBid (timeouts of 300ms and 305ms).
Prebid loads the first requestBid and triggers calls to the bidders. In the mean time we call the next one, prebid adds it to the bidRequestQueue. When the first one ends (or timeout) prebid calls "bidmanager.executeCallback();" which calls the callback function ( bidsBackHandler ), and then clearAuction() which calls the next bidRequest in the queue and then the callback is cleared (and here lies the bug).
When clearAution is called and next request is triggered the new bidsBackHandler is set up before the previous one is cleared meaning that executeCallback() is clearing actually the current one, the consequence is that when the second request ends there is no bidsBackHandler to be called and prebid is not enable to trigger requestBid anymore.
Example showing the bug: https://jsfiddle.net/anxobotana/tu2rn94x/
Example using the fix: https://jsfiddle.net/anxobotana/tu2rn94x/1/
The fix i applied moves the line clearing externalOneTimeCallback before clearAuction in bidmanager.js ( line ~279 ):
finally {
$$PREBID_GLOBAL$$.clearAuction();
externalOneTimeCallback = null;
}
for:
finally {
externalOneTimeCallback = null;
$$PREBID_GLOBAL$$.clearAuction();
}
thanks
Thanks for the submission I'll have a look.
Thanks, I've opened a PR with this change.