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 race condition in modularity test #3421

Merged
merged 3 commits into from
Jan 23, 2024
Merged

Fix race condition in modularity test #3421

merged 3 commits into from
Jan 23, 2024

Conversation

VeronikaSolovei9
Copy link
Contributor

Possible fix for race condition in TestModulesCanBeExecutedForMultipleBiddersSimultaneously

It seems that in this test, there were two possible sources of problems:

  1. There appeared to be a typo where a bidder name was duplicated.
  2. bidderImpl object was shared between bidder requests.

The bidder requests are being tested in separate, concurrent goroutines, causing concurrent reads and writes to the Headers map.

The fix is to fix the typo, and to create separate objects.

One thing that is not entirely clear to me is that the Headers map is being cloned inside of the getAllBids function, and according to my investigation with breakpoints and the debug log, the error was happening in an Add method after the clone. Nonetheless, upon repeated testing, I cannot reproduce the bug after the above changes.

@VeronikaSolovei9
Copy link
Contributor Author

I suspect something is not working as expected in func (h Header) Clone() Header { when input header in not nil and empty.

@VeronikaSolovei9 VeronikaSolovei9 changed the title Fix rece condition in test Fix race condition in test Jan 23, 2024
@bsardo bsardo self-assigned this Jan 23, 2024
Copy link
Collaborator

Choose a reason for hiding this comment

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

The changes here look good but I think they only partially resolve the issue as I was still getting failures when running this test with race detection enabled. To fix this, I think we need to update the two mutations in mockUpdateBidRequestHook function HandleBidderRequestHook so that payload.request.Site is cloned prior to writing to Name and Domain:

c.AddMutation(
	func(payload hookstage.BidderRequestPayload) (hookstage.BidderRequestPayload, error) {
		site := ptrutil.Clone(payload.Request.Site)
		site.Name = "test"
		payload.Request.Site = site
		return payload, nil
	}, hookstage.MutationUpdate, "bidRequest", "site.name",
).AddMutation(
	func(payload hookstage.BidderRequestPayload) (hookstage.BidderRequestPayload, error) {
		site := ptrutil.Clone(payload.Request.Site)
		site.Domain = "test.com"
		payload.Request.Site = site
		return payload, nil
	}, hookstage.MutationUpdate, "bidRequest", "site.domain",
)

@bsardo bsardo changed the title Fix race condition in test Fix race condition in modularity test Jan 23, 2024
@bsardo bsardo merged commit 498955b into master Jan 23, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants