Skip to content

Unexpected behavior with asynchronous execution of sync hooks #42

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

Open
dgirardi opened this issue Mar 6, 2025 · 1 comment
Open

Unexpected behavior with asynchronous execution of sync hooks #42

dgirardi opened this issue Mar 6, 2025 · 1 comment

Comments

@dgirardi
Copy link

dgirardi commented Mar 6, 2025

Consider this:

const hook = funHooks();
const fn = hook('sync', (arg) => {
  console.log('inner', arg);
});
fn.before((next, arg) => {
  console.log('outer', arg);
  setTimeout(() => {
    next(arg)
  })
});
fn(1);
fn(2);

The output is:

outer 1
outer 2
inner 1
inner undefined

while I'd expect the last line to be inner 2.

From the README:

Also, if you're hooking a function with sync your hooks should all call next synchronously (e.g. no ajax) so that your value can be returned. If you asynchronously call next in a sync hook then the return value will be undefined.

it's clear that this is not intended usage, but not clear that it's not just the return value that's affected. Perhaps the note should be updated to say "your hooks MUST all call next synchronously"?

@snapwich
Copy link
Owner

snapwich commented Mar 6, 2025

yeah i agree with you. i suppose i didn't code for this very well or include any tests for this use case since it's not intended usage, but the undefined behavior does look odd. i would have expected the same output that you expected. i'll take a look and see if there's not a way to make the unexpected usage act more predictably at least, maybe add a test case. the documentation can be updated easily though for sure!

patmmccann pushed a commit to prebid/Prebid.js that referenced this issue Apr 11, 2025
…a` (#12839)

* PAAPI: support for auction nonces in buildPAAPIConfigs

* core: allow async processing around buildRequests

* PAAPI: respect greedyPromise in parallelPaapiProcessing

* PAAPI: resolve nonces on adapter request & response

* resolve auction nonces

* Use async hook for processBidderRequest (snapwich/fun-hooks#42)

* lint

* remove superfluous setTimeotu

* revert changes

* PAAPI: introduce paapiParameters API

* remove unnecessary postBuildRequests

* add support for getInterestGroupAdAuctionData

* Fix unnecessary this aliasing

* add serverResponse to async signals
patmmccann added a commit to prebid/Prebid.js that referenced this issue Apr 16, 2025
* update: Remove the outdated publisher ID field and the code responsible for macro replacement. (#12) (#12905)

fixed test (#13)

clean up

* Teads Bid Adapter : send outbrain id (#12891)

* Teads: Send outbrain id

* retrigger checks

* retrigger checks

* retrigger checks

* retrigger checks

* Prebid 9.36.0 release

* Increment version to 9.37.0-pre

* Add 2 new sizes to Rubicon Adapter (#12910)

* ResetDigital Bid Adapter: keywords params validation (#12909)

* fix(resetdigitalBidAdapter): handle keywords parameter as array or string

Fix a bug in resetdigitalBidAdapter where it would throw an error when the keywords parameter was provided as an array instead of a string. This change adds type checking to properly handle string formatting, preventing code flow from being disrupted.

* updating condition to support arrays

* Browsi RTD & Analytics Adapters : improvements (#12815)

* browsiRtdProvider-improvements

* browsiRtdProvider-improvements

* browsiRtdProvider-improvements

* browsiRtdProvider-improvements

* browsiRtdProvider-improvements

* browsiRtdProvider-improvements

* browsiRtdProvider-improvements

* browsiRtdProvider-improvements

* browsiRtdProvider-improvements

* browsiRtdProvider-improvements

* browsiRtdProvider-improvements

* browsiRtdProvider-improvements

* browsiRtdProvider-improvements

* browsiRtdProvider-improvements

* browsiRtdProvider-improvements

---------

Co-authored-by: Stav Ben Shlomo <[email protected]>

* Goldbach Bid Adapter : switching to ortb endpoint, added uid when consent is granted (#12847)

* implemented openRTB base for goldbach adapter

* implemented passing of custom parameters

* added fallbacks and additional mapping for response values

* added gdpr mapping

* removed logs

* updated passing of vastXML / vastURL

* added tests and cookie sync

* added uid generation and extended tests

* updated outstream renderer options

* updated logging and outstream player params

* adjusted tests and bidder, removed pre-ortb content

* Revert "Goldbach Bid Adapter : switching to ortb endpoint, added uid when con…" (#12915)

This reverts commit 34704a0.

* PubMatic Bid Adapter : analyse bid adjustment patterns  (#12906)

* PubMatic Bid Adapter: Set BidAdjustment on BidWon event in root level ext object

* Update fallback for mediaType and names of field

* Update cpmAdjustment object for reporting

* Add Unit test case for onBidWon function

---------

Co-authored-by: Komal Kumari <[email protected]>

* UNIQUEST Bid Adapter: initial release (#12846)

* add uniquestBidAdapter,uniquestAnalyticsAdapter

* fix test sid

* Core: Local cache for video bids (#12598)

* Local cache for video bids

* clean up

* clean up

* fix

* error message update

* revoking blobs on auction expiry

* Local cache + GAM poc

* ima sdk adsResponse

* local cache logic

* dfp function & examples & unit tests

* fix order

* reorganization

* refactor

* lint fix

* introducing setAdXml

* renderBid change

* removing getVast from pbjs

* review fixes

* limiting use of prefetching vast to local cache

* revert not needed

* adapting to 'send all  bids', adding some tests

* + regexp

* regexp fix

* regexp fix

* uuid matching refactor

* Update integrationExamples/videoModule/jwplayer/localVideoCache.html

Co-authored-by: Karim Mourra <[email protected]>

* remove unecessary parts

* lint fix

* remove not needed test

---------

Co-authored-by: Karim Mourra <[email protected]>

* PAAPI: parallel auction missing async signals (#12887)

Co-authored-by: v.raybaud <[email protected]>

* Endpoint updated (#12920)

* PubxAI RTD Module : update docs (#12921)

* send BidRejected Events to capture floored bids

* fix tests

* send pubx_id as query param

* added extraData in analytics adapter to be sent in beacon data

* added extraData in analytics adapter to be sent in beacon data

* moved data read to session storage

* bumped version

* moving all data to localStorage again

* updated test cases for pubxaiAA.js

* fixing the missing logging of invalid bids

* remove endpoint as optional

---------

Co-authored-by: Phaneendra Hegde <[email protected]>
Co-authored-by: NikhilX <[email protected]>
Co-authored-by: Nathan Oliver <[email protected]>

* Contxtful Rtd Provider : add ad unit positions (#12792)

* feat: adunitpos

* fix: unused variable

* doc: update

* doc: space

* feat: ortb2 fragment

* refactor: use getBoundingClientRect

* doc: js

---------

Co-authored-by: rufiange <[email protected]>

* added medianet in codepath-notification (#12913)

* Adds a flag to suppress losing bid custom targeting values (#12911)

* PubMatic RTD Provider - Initial Release (#12732)

* Initial release PubMatic RTD

* PubMatic RTD: Update browser regex mapping and add description in md file

* PubMatic RTD: Add country in floor schema, use client hint for browser, log ctr in logger

* PubMatic Analytics : Update browser mapping

* PubMatic RTD: Update md file, browser regex, browser test cases

* PubMatic Analytics: Handle null checks

* Pubmatic RTD : set ext in ortb2 only when country is present

* Pubmatic RTD : Update md file

* Pubmatic RTD : delete endpoint property from floors

---------

Co-authored-by: Komal Kumari <[email protected]>

* NodalsAi Rtd Module : integrate with major version 1 of Nodals' JS Library (#12912)

* Additional method proxying

* Update version to use latest major verson pattern matching

* Fix tests

* Cleaned up tests

* Linting

* Rename parameter passed to getBidRequestData to match documentation

* Removing overly verbose log messages

* linting

---------

Co-authored-by: slimkrazy <[email protected]>

* adds generic open pair support (#12599)

Co-authored-by: Miguel Morales <[email protected]>

* Adgrid Bid Adapter : add new param placement (#12901)

* Added new optional param placement

* Placement params is required now

* Robusta Bid Adapter: New bid adapter (#12797)

* robustaBidAdapter: New bid adapter

* fix: robusta lint issues

* consentManagementTcf: do not require CMP API to be available when Prebid loads (#12922)

* LiveIntent User ID Module And Analytics Adapter: Built-in Treatment/Holdout Mechanism And Auction Events Collection Improvements (#12856)

* Adjust the analytics adapter

* Trigger Build

* Trigger Build

* Update adloader.js (#12929)

* PBS Bid Adapter : add BEFORE_PBS_HTTP event (#12889)

* Add pbs before http event

* Fix tests

---------

Co-authored-by: Patrick McCann <[email protected]>

* Prebid 9.37.0 release

* Increment version to 9.38.0-pre

* Ozone Bid Adapter : support vastURL & vastXML (#12936)

* Update ozoneBidAdapter.js

support for vastXML/vastURL

* Update ozoneBidAdapter_spec.js

updated spec test

* New RTD submodule: optableRtdProvider (#12850)

* Optable RTD submodule: Initial commit

* fix typo: user.ext.data -> user.data

* Optable RTD submodule: Restrict insecure bundle URLs

* optableRtdProvider doc: add a note to erase optable.ext. custom fields

* Optable RTD submodule: Change the method of passing extra data

---------

Co-authored-by: Bohdan V <[email protected]>
Co-authored-by: Eugene Dorfman <[email protected]>

* Smaato: Add iframe UserSyncs (#12924)

* Build system: clear event log between test suites (#12946)

* NewsPassID Bid Adapter: refactor (#12923)

* newspassidBidAdapter refactor

* update to use setBidderConfig

* revert to legacy params publisherId, placementId

* StackAdapt Bid Adapter: initial release (#12896)

* inital stackadapt bidder adapter

* review - text/plain, floors module, endpoint

* review - redundant checks

* NodalAiRtdModule:  stricter consent checks (#12931)

* fix: stricter consent checks

* Updated consent checks

---------

Co-authored-by: slimkrazy <[email protected]>

* Optable RTD submodule: check for cached data before firing a request (#12954)

Co-authored-by: Bohdan V <[email protected]>

* Core tests: eliminate some sinon.reset (#12942)

* Update cmpClient_spec.js: eliminate sinon.reset

* Update cmpClient_spec.js

* Update redactor_spec.js

* Update cmpClient_spec.js

* Update translator_spec.js

* Update adapterManager_spec.js

* Update adapterManager_spec.js

* Update adapterManager_spec.js

* Update cmpClient_spec.js

* Update adapterManager_spec.js

* Update adapterManager_spec.js

* Update adapterManager_spec.js

* Update adapterManager_spec.js

* Update translator_spec.js

* Update cmpClient_spec.js

* Update redactor_spec.js

* Vistars bid adapter: initial release (#12813)

* Vistars bid adapter

* fix: video bid testing

* fix: consent parameters names

* fix: remove unneeded code

* Criteo Bid Adapter: Use optional chaining for callbacks (#12950)

Avoids errors when callbacks are not iterable.

Closes #12949

* Build system: setup dist directory for NPM release (#12959)

* Build system: setup dist directory for NPM release

* Fix .npmignore

* Adtrgtme Bid Adapter: function renaming (#12958)

* Adtrgtme Bid Adapter: function renaming

* adtrgtme version changes

* fix version

* skip pb client version check

* Prebid 9.38.0 release

* Increment version to 9.39.0-pre

* PubMatic RTD : fixed unit test cases (#12962)

* Fixed test cases for pubmatic RTD

(cherry picked from commit 163fc56)

* Add space

---------

Co-authored-by: Komal Kumari <[email protected]>

* Yandex Bid Adapter : pass document language as site.content.language ortb parameter (#12918)

* Yandex bid adapter: Pass document language as 'banner-lang' query parameter

Add an additional query parameter 'banner-lang' to handle the language of the page being viewed by the user

* add documentLang enrichment parameter

* set document lang to ortb.site.content.language in yandex bid adapter

* minor fix

* pass content language as language fallback in yandex bid adapter

* pass document language to request params instead of site.content.language

* minor fixes

* minor fix

* use deepSetValue to store documentlang into site content lang

* minor fixes

* unit test fixes

* minor fix

* change ext.prebid.bidRequest.params.documentLang to site.ext.data.documentLang

* placement support added (#12953)

Co-authored-by: Gabriel Chicoye <[email protected]>

* CondorX Bid Adapter: add subid (#12972)

* Add subid

* Spacing

* AdagioBidAdapter: add support for instl, rwdd ortb2 signals (#12961)

* added user agent and structured user agent to request (#12969)

* MAINTAG-321 (#12976)

Issue Switching Prebid Version – Citynews (76d8a3332520158)

* Missena Bid Adapter : refactor payload to use ORTB2 (#12977)

* Dochase Bid Adapter : Initial Release (#12803)

* Audiencelogy Bid Adapter : Initial Release

* removed duplicates

* removed duplicates

* added common code in library libraries/audiencelogyUtils

* solved linter issues

* imported getRequest from library and solved linting issue

* solved trailing space issue

* new adapter : lane4

* new adapter : lane4

* removed linter errors

* removed trailing space

* Dochase Bid Adapter : initial release

* changed the comment

* Bugfix: Update adRendering.js styling for iframe in case of insterstitial ads (#12975)

* update styling for frame in case of instl ads

* Revert "update styling for frame in case of instl ads"

This reverts commit 0470efc.

* AdRendering file update for interstitial iframe handling

* Revert "AdRendering file update for interstitial iframe handling"

This reverts commit 6473929.

* adding style without relying on frame id and display:block

* Update style.width/height in direct rendering

* Core: set instl flag on bid responses

* Core: do not resize remote creative frames for interstitials

* Core: include instl flag in cross-frame messages

* Revert "adding style without relying on frame id and display:block"

This reverts commit d957586.

* iframe handling for missing safeframes

* core: resize interstitials' inner iframe

---------

Co-authored-by: ubaid <[email protected]>
Co-authored-by: Demetrio Girardi <[email protected]>

* Brave Bid Adapter : add support for bidfloor and eids (#12971)

* eids and bidfloor support update BraveAdapter

* eids and bidfloor support update BraveAdapter

* fix points test on spec test file

---------

Co-authored-by: root <[email protected]>

* Core: Getting window dimensions unification (#12925)

* Core: Getting window dimensions unification

* event handler

* method signature change

* test fix

* test fix

* removing listeners, adding time check

---------

Co-authored-by: Patrick McCann <[email protected]>

* MediaEyes Bid Adapter : initial release (#12899)

* init mediaEyesBidAdapter

* fix camel case

* renamefile

* fix and update bid adpater

* fix getBidFloor

* add more test

* Medianet Analytics & Adapter : refactor to shared utils (#12968)

* refactor: clean up Medianet analytics and adapter

* fix: resolve merge conflicts after merging with master

* Core: use 'async' hooks for asynchronous hooks (#12933)

* PubmaticRTDProvider: read and apply configurations (#12984)

* Update pubmaticAnalyticsAdapter.js

* Update pubmaticAnalyticsAdapter_spec.js

* Update pubmaticAnalyticsAdapter.js

* Update pubmaticRtdProvider.js

* Update pubmaticRtdProvider_spec.js

* Update pubmaticRtdProvider_spec.js

* Equativ Bid Adapter: add DSP cookie sync (#12787)

* add user sync

* use local storage instead of cookies

* update equativ adapter u.t.

* fix equativ adapter u.t.

---------

Co-authored-by: Krzysztof Sokół <[email protected]>

* Fix: vastTracker url to have updated cpm (#12833)

* Prebid 9.39.0 release

* Increment version to 9.40.0-pre

* AdSpirit Bid Adapter : updated version with native support (#12776)

* Video is added

* Update adspiritBidAdapter.js

Updates js file with native support

* Update adspiritBidAdapter.md

Updated md file with new information related to native

* Update adspiritBidAdapter_spec.js

Adspirit updated test case with native support

* Update adspiritBidAdapter.md

A new description related to native has been added to adspiritBidAdapter.md.

* Update adspiritBidAdapter.js

adspirit.js file updated with getWinDimensions

* Update adspiritBidAdapter_spec.js

Updated Test cases with Native support

* Update adspiritBidAdapter.js

adspirit.js file updated with screen width and height

---------

Co-authored-by: sivamatta94 <[email protected]>

* semantiqRtdProvider: avoid adding default company ID if companyId parameter is present (#12985)

Co-authored-by: Alexandr Kim <[email protected]>

* Previous auction module: added new highestBidCurrency field to payloads (#12988)

* added new highestBidCurrency field to prev auct info payloads

* changed bidderErrorCode to rejectionReason

* Snigel Bid Adapter: delegate consent-related checks to user sync iframe (#12990)

* semantiqRtdProvider: dispatch page impression event on initialization (#12989)

Co-authored-by: Alexandr Kim <[email protected]>

* PAAPI: support `createAuctionNonce` and `getInterestGroupAdAuctionData` (#12839)

* PAAPI: support for auction nonces in buildPAAPIConfigs

* core: allow async processing around buildRequests

* PAAPI: respect greedyPromise in parallelPaapiProcessing

* PAAPI: resolve nonces on adapter request & response

* resolve auction nonces

* Use async hook for processBidderRequest (snapwich/fun-hooks#42)

* lint

* remove superfluous setTimeotu

* revert changes

* PAAPI: introduce paapiParameters API

* remove unnecessary postBuildRequests

* add support for getInterestGroupAdAuctionData

* Fix unnecessary this aliasing

* add serverResponse to async signals

* BeOp Bid Adapter: support getUserSyncs (#12944)

* Add getUserSyncs in BeOpBidAdapter

* Migrate domain from beop.io to collectiveaudience.co

* Multiple Frame tracking capacity

* PubMatic Adapter : Using ORTB Converter library for request/response handling (#12814)

* Pubmatic Adapter with ORTB Converter Library

* Pubmatic Adapter with ORTB Converter Library

* Support media type based floor

* Support media type based floor

* Linting fixes

* Added cpm adjustment details to next auction

* Added test cases for cpm adjustment

* Fix for undefined adslot case

* Adipolo Bid Adapter : initial release (#12883)

* add adipolo Adapter

* without aliases

* retrigger checks

* retrigger checks

* retrigger checks

* retrigger checks

* fix test

* retrigger checks

---------

Co-authored-by: Chucky-choo <[email protected]>

* SSP_Genie Bid Adapter : ID5 Compatible Adapter (#12974)

* modify adUnit infomation

* fix imuid module

* feat(GenieeBidAdapter): Add support for GPID and pbadslot

- Add support for GPID (Global Placement ID) from ortb2Imp.ext.gpid
- Add fallback support for ortb2Imp.ext.data.pbadslot
- Include gpid parameter in request when GPID exists
- Add test cases to verify GPID, pbadslot, and priority behavior

* Aladdin Bidder ID5 Compatible Adapter

* add comment

* modified test message

* the import of buildExtuidQuery was missing

* test: add test cases for id5id in extuid query

* delete duplicate test

---------

Co-authored-by: Murano Takamasa <[email protected]>
Co-authored-by: daikichiteranishi <[email protected]>
Co-authored-by: teranishi daikichi <[email protected]>
Co-authored-by: gn-daikichi <[email protected]>
Co-authored-by: takumi-furukawa <[email protected]>
Co-authored-by: furukawaTakumi <[email protected]>
Co-authored-by: furukawaTakumi <[email protected]>
Co-authored-by: haruki-yamaguchi <[email protected]>

* Kobler bid adapter: pass cid in bid response. (#12999)

* Prebid 9.40.0 release

* Increment version to 9.41.0-pre

---------

Co-authored-by: zeeye <[email protected]>
Co-authored-by: Mickaël Leclerc <[email protected]>
Co-authored-by: Prebid.js automated release <[email protected]>
Co-authored-by: Michael Wilson <[email protected]>
Co-authored-by: Jhon <[email protected]>
Co-authored-by: Stav Ben Shlomo <[email protected]>
Co-authored-by: Stav Ben Shlomo <[email protected]>
Co-authored-by: Ben Brachmann <[email protected]>
Co-authored-by: Chris Huie <[email protected]>
Co-authored-by: Komal Kumari <[email protected]>
Co-authored-by: Komal Kumari <[email protected]>
Co-authored-by: kazutoshi-uekawa-muneee <[email protected]>
Co-authored-by: mkomorski <[email protected]>
Co-authored-by: Karim Mourra <[email protected]>
Co-authored-by: Vincent <[email protected]>
Co-authored-by: v.raybaud <[email protected]>
Co-authored-by: Nikhil <[email protected]>
Co-authored-by: Tej <[email protected]>
Co-authored-by: Phaneendra Hegde <[email protected]>
Co-authored-by: NikhilX <[email protected]>
Co-authored-by: Nathan Oliver <[email protected]>
Co-authored-by: sebastienrufiange <[email protected]>
Co-authored-by: rufiange <[email protected]>
Co-authored-by: Monis Qadri <[email protected]>
Co-authored-by: Sam Evans <[email protected]>
Co-authored-by: Samuel Adu <[email protected]>
Co-authored-by: slimkrazy <[email protected]>
Co-authored-by: Miguel <[email protected]>
Co-authored-by: Miguel Morales <[email protected]>
Co-authored-by: Md. Soman Mia Sarker <[email protected]>
Co-authored-by: robustadev <[email protected]>
Co-authored-by: Demetrio Girardi <[email protected]>
Co-authored-by: Viktor Dreiling <[email protected]>
Co-authored-by: Sir-Will <[email protected]>
Co-authored-by: Rupesh Lakhani <[email protected]>
Co-authored-by: Antoine Niek <[email protected]>
Co-authored-by: Bohdan V <[email protected]>
Co-authored-by: Eugene Dorfman <[email protected]>
Co-authored-by: Bernhard Bohne <[email protected]>
Co-authored-by: Erik <[email protected]>
Co-authored-by: Ben Boonsiri <[email protected]>
Co-authored-by: hamper <[email protected]>
Co-authored-by: Graham Higgins <[email protected]>
Co-authored-by: tarasmatokhniuk <[email protected]>
Co-authored-by: Maxim Yermolayev <[email protected]>
Co-authored-by: Gabriel Chicoye <[email protected]>
Co-authored-by: Gabriel Chicoye <[email protected]>
Co-authored-by: CondorXIO <[email protected]>
Co-authored-by: Olivier <[email protected]>
Co-authored-by: Tommy Pettersen <[email protected]>
Co-authored-by: f-cali <[email protected]>
Co-authored-by: Petre Damoc <[email protected]>
Co-authored-by: hasanideepak <[email protected]>
Co-authored-by: Muhammad Ubaid <[email protected]>
Co-authored-by: ubaid <[email protected]>
Co-authored-by: Sacha <[email protected]>
Co-authored-by: root <[email protected]>
Co-authored-by: giathinhly <[email protected]>
Co-authored-by: pratik.ta <[email protected]>
Co-authored-by: priyankadeshmane <[email protected]>
Co-authored-by: janzych-smart <[email protected]>
Co-authored-by: Krzysztof Sokół <[email protected]>
Co-authored-by: carsten1980 <[email protected]>
Co-authored-by: sivamatta94 <[email protected]>
Co-authored-by: Alexandr Kim <[email protected]>
Co-authored-by: Alexandr Kim <[email protected]>
Co-authored-by: Jason Quaccia <[email protected]>
Co-authored-by: Snigel <[email protected]>
Co-authored-by: SebRobert <[email protected]>
Co-authored-by: kapil-tuptewar <[email protected]>
Co-authored-by: Pavlo Kavulych <[email protected]>
Co-authored-by: Chucky-choo <[email protected]>
Co-authored-by: haruki yamaguchi <[email protected]>
Co-authored-by: Murano Takamasa <[email protected]>
Co-authored-by: daikichiteranishi <[email protected]>
Co-authored-by: teranishi daikichi <[email protected]>
Co-authored-by: gn-daikichi <[email protected]>
Co-authored-by: takumi-furukawa <[email protected]>
Co-authored-by: furukawaTakumi <[email protected]>
Co-authored-by: furukawaTakumi <[email protected]>
Co-authored-by: haruki-yamaguchi <[email protected]>
Co-authored-by: Bendegúz Ács <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants