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

Concurrency Issue with ModuleContext in BidderRequest Hook #4239

Open
ulphidius opened this issue Feb 26, 2025 · 1 comment
Open

Concurrency Issue with ModuleContext in BidderRequest Hook #4239

ulphidius opened this issue Feb 26, 2025 · 1 comment

Comments

@ulphidius
Copy link

During some tests with a custom module, i encountered an issue with the use of ModuleContext.
In the BidderRequest hook, when I attempt to replace data from the ModuleContext, i encounter a concurrency issue:

fatal error: concurrent map read and map write

This issue makes sense because I retrieve data stored under a key in the map and then try to update it after performing some operations. Since BidderRequest is triggered for every bidder and the ModuleContext is shared across all hooks of the module, this concurrency problem arises.
I guess that will happen to the RawBidderResponse as well.

Theoretically, it is possible to replace ModuleContext with a sync.Map, but this would introduce some performance issues.

Is this behavior intentional ?

@linux019
Copy link
Contributor

linux019 commented Mar 8, 2025

I faced the same issue because the stage 'bidder request' shares the same module context across all bidder goroutines.
If a hook ends up with a timeout or error, its modification results in the module context should be discarded. I think the easiest way to address this is to add a sync.RWMutex to the module context and expose its lock/rlock/runlock/unlock methods to the modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Research
Development

No branches or pull requests

3 participants