From eb7febb0afbcc51a3d357b0c201965cbe7357523 Mon Sep 17 00:00:00 2001 From: Gus Carreon Date: Wed, 17 Mar 2021 13:26:46 -0400 Subject: [PATCH 1/2] Fix race condition in Beachfront adapter --- adapters/beachfront/beachfront.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/adapters/beachfront/beachfront.go b/adapters/beachfront/beachfront.go index 3a431c9cf3a..76cc3ac7d4d 100644 --- a/adapters/beachfront/beachfront.go +++ b/adapters/beachfront/beachfront.go @@ -407,8 +407,12 @@ func getVideoRequests(request *openrtb.BidRequest) ([]beachfrontVideoRequest, [] bfReqs[i].Request = *request var secure int8 + var deviceCopy *openrtb.Device if bfReqs[i].Request.Device == nil { - bfReqs[i].Request.Device = &openrtb.Device{} + deviceCopy = &openrtb.Device{} + } else { + device := *bfReqs[i].Request.Device + deviceCopy = &device } if beachfrontExt.VideoResponseType == "nurl" { @@ -416,13 +420,15 @@ func getVideoRequests(request *openrtb.BidRequest) ([]beachfrontVideoRequest, [] } else { bfReqs[i].VideoResponseType = "adm" - if bfReqs[i].Request.Device.IP == "" { - bfReqs[i].Request.Device.IP = fakeIP + if deviceCopy.IP == "" { + deviceCopy.IP = fakeIP } } if bfReqs[i].Request.Site != nil && bfReqs[i].Request.Site.Domain == "" && bfReqs[i].Request.Site.Page != "" { - bfReqs[i].Request.Site.Domain = getDomain(bfReqs[i].Request.Site.Page) + siteCopy := *bfReqs[i].Request.Site + siteCopy.Domain = getDomain(bfReqs[i].Request.Site.Page) + bfReqs[i].Request.Site = &siteCopy secure = isSecure(bfReqs[i].Request.Site.Page) } @@ -437,10 +443,11 @@ func getVideoRequests(request *openrtb.BidRequest) ([]beachfrontVideoRequest, [] } } - if bfReqs[i].Request.Device != nil && bfReqs[i].Request.Device.DeviceType == 0 { + if deviceCopy != nil && deviceCopy.DeviceType == 0 { // More fine graned deviceType methods will be added in the future - bfReqs[i].Request.Device.DeviceType = fallBackDeviceType(request) + deviceCopy.DeviceType = fallBackDeviceType(request) } + bfReqs[i].Request.Device = deviceCopy imp := request.Imp[i] From a32d05809e60bfc1efed601aebbfe9729e814bdc Mon Sep 17 00:00:00 2001 From: Gus Carreon Date: Thu, 18 Mar 2021 10:53:12 -0400 Subject: [PATCH 2/2] Removed nil check and simplified --- adapters/beachfront/beachfront.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/adapters/beachfront/beachfront.go b/adapters/beachfront/beachfront.go index 76cc3ac7d4d..620244a1279 100644 --- a/adapters/beachfront/beachfront.go +++ b/adapters/beachfront/beachfront.go @@ -407,12 +407,11 @@ func getVideoRequests(request *openrtb.BidRequest) ([]beachfrontVideoRequest, [] bfReqs[i].Request = *request var secure int8 - var deviceCopy *openrtb.Device + var deviceCopy openrtb.Device if bfReqs[i].Request.Device == nil { - deviceCopy = &openrtb.Device{} + deviceCopy = openrtb.Device{} } else { - device := *bfReqs[i].Request.Device - deviceCopy = &device + deviceCopy = *bfReqs[i].Request.Device } if beachfrontExt.VideoResponseType == "nurl" { @@ -443,11 +442,11 @@ func getVideoRequests(request *openrtb.BidRequest) ([]beachfrontVideoRequest, [] } } - if deviceCopy != nil && deviceCopy.DeviceType == 0 { + if deviceCopy.DeviceType == 0 { // More fine graned deviceType methods will be added in the future deviceCopy.DeviceType = fallBackDeviceType(request) } - bfReqs[i].Request.Device = deviceCopy + bfReqs[i].Request.Device = &deviceCopy imp := request.Imp[i]