In yahoo-finance2 v3+, the library uses an instance-based API via new YahooFinance(options). Each instance is intended to have its own isolated state, including its own cookieJar, logger, and queue options.
However, users should be aware of potential state leakage if multiple instances are used in a single process (e.g., in multi-tenant environments where each user has a different session, proxy, or region). Key areas where state might be shared across instances include:
- Crumb Cache: The
crumb and its associated promise are cryptographically paired with cookies in a cookieJar. If instances share a crumb but use different cookie jars, Yahoo may reject requests with a 401 "Invalid Crumb" error. - Request Queue: All instances may funnel through a single global
_queue. If different instances have different concurrency or interval settings, they may conflict as the last instance to run assertQueueOptions wins. - Quote Combine Debounce Map: The
slugMap used for debouncing calls might be shared. This can cause requests from one instance to be merged into a batch executed using the context (cookie jar, fetch options, logger) of a different instance.
To ensure proper isolation, ensure each YahooFinance instance is provided with its own unique cookieJar in the options object.