Prebid.js icon indicating copy to clipboard operation
Prebid.js copied to clipboard

Race condition when calling requestBids multiple times

Open gramorris opened this issue 10 years ago • 9 comments

Hi,

We use the disableInitialLoad on GPT feature but we also load ads up in groups depending on the device, so we load a leaderboard and an mpu in the head as they exist on all devices and then on desktop we might load an additional mpu and a sky ad as they are drawn on screen.

In 0.8.1 this behaviour works fine, however in 0.9.2 through to 0.11.0 adverts are failing in renderAd with "ERROR: Error trying to write ad. Cannot find ad by given id : 31fe525abd64c6".

What is happening is we call requestBids, bids come in and GPT is called. While DFP is off doing it's thing a second requestBids is called and starts a new auction. The first request then comes back from DFP with a call to renderAd but the ad no longer exists in prebid.

The problem code is the clearing bidsRequested and bidsReceived at the top of the requestBids function.

6aa89378-32f8-11e6-9ad9-222401bb9525 6aa7b08e-32f8-11e6-82c0-864128acd811

gramorris avatar Jul 27 '16 13:07 gramorris

I'm also seeing this issue. I was able to work around it by adding an event handler to the 'SlotRenderEndedEvent' googletag event and not firing off a new requestBids until all the previously requested ads had actually loaded but this seems like a kludged way to handle it.

jalbersmead avatar Jul 27 '16 17:07 jalbersmead

We're still on 0.8.1. We are considering how to figure out the ads in to a single bid request call but can't rationalise how it would work in infinite scroll situations where this condition could still occur.

@jalbersmead I'd assumed that SlotRenderEndedEvent only gets called when a PreBid ad is rendered, is it possible that your second request would not ever fire if the ad impressions were bought by AdX in DFP?

gramorris avatar Jul 27 '16 21:07 gramorris

PR #477 should be merged to master soon and this will queue bid requests. This should address this issue by waiting for the current request to come back through renderAd before sending out the next request for bids.

protonate avatar Aug 02 '16 23:08 protonate

Thanks, I'll check it out.

Initial thoughts are: what would the impact be if AdX wins the bids in DFP and renderAd is not called? does the queue rely on all the slots in the request returning to renderAd or just one - if it's all what's the impact if the request to DFP fails?

gramorris avatar Aug 03 '16 09:08 gramorris

renderAd will be called when all bids are back for a given slot, or the timeout is reached. We don't wait for all slots in the auction to have bids back. The impact of the case where the DFP call is made just prior to another auction being run for the same slot then the first ad will be rendered only until the second ad is returned, or not at all. Solving for this issue is problematic without making some broad assumptions, such as what an ad "time to live" aught to be, if anything. We are discussing this in further detail and are open to ideas.

protonate avatar Aug 09 '16 19:08 protonate

The SlotRenderEndedEvent used by @jalbersmead seems a good option for DFP implementations, that could make it's way into Prebid, but doesn't solve this for Prebid more generally.

protonate avatar Aug 09 '16 19:08 protonate

@gramorris This should be resolved in master now. Please let us know if you still are seeing this behavior.

mkendall07 avatar Aug 17 '16 22:08 mkendall07

@mkendall07

Thanks Matt, initial testing shows resolved, I'll dig in a bit more over the next few days but looks good at the moment.

gramorris avatar Aug 18 '16 09:08 gramorris

Closing as resolved, if any additional issues please reopen or create a new issue.

protonate avatar Aug 18 '16 22:08 protonate