go-bitswap icon indicating copy to clipboard operation
go-bitswap copied to clipboard

chore: rewrite ProviderQueryManager and rename to ProviderQueryer

Open guseggert opened this issue 3 years ago • 0 comments

This renames ProviderQueryManager to ProviderQueryer to more clearly reflect what it does.

It also rewrites it to remove the need for running a goroutine pool. Instead, concurrency is limited using a semaphore and locks are used to ensure that only a single query happens under concurrent requests for the same CID. This simplifies the code, makes reading stack traces easier, and removes the need for lifecycle management of the queryer (the only resources that need to be shut down are done so by the request context).

Some other minor changes:

  • Uses a mockable clock so that unit tests aren't racy
  • Adds a fuzzing test to check for races and deadlocks
  • Instead of buffering providers for every receiver to avoid blocking a broadcast, this uses a dynamic select to achieve the same thing without having to buffer copies

guseggert avatar Aug 15 '22 18:08 guseggert