Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(baileys): defuse the abandoned version fetch and record the change

Yudhi Armyndharis8d232d2d2171
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 91519f7fc..096fc2919 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
+- The Baileys engine resolves its WhatsApp Web version through a fallback chain instead of one call: an operator pin (`BAILEYS_WA_VERSION`), the two library endpoints, a disk cache of the last known-good version, then a built-in default. Each remote tier is bounded and rides the session proxy, and a stale answer is neither cached nor used.
- The Go and Java SDKs can @mention on an audio send. `SendAudioRequest` was flattened off the shared media type and lost the field, so the typed path could not set it while every other client could.
- Three routes declare the `409` they can answer: a duplicate template name on create or rename, and an integration instance id that already exists. Clients generated from the contract modelled those calls as unable to conflict.
- `DOMAIN` is dropped from `.env.example`. Nothing read it, so an operator setting it to their real hostname changed nothing.
diff --git a/src/engine/adapters/baileys-version-resolver.ts b/src/engine/adapters/baileys-version-resolver.ts
index b6323fb12..87200c1f4 100644
--- a/src/engine/adapters/baileys-version-resolver.ts
+++ b/src/engine/adapters/baileys-version-resolver.ts
@@ -143,6 +143,9 @@ export class BaileysVersionResolver {
let timeoutId: NodeJS.Timeout | undefined;
const timeoutPromise = new Promise<never>((_, reject) => {
timeoutId = setTimeout(() => reject(new Error('fetchLatestBaileysVersion timeout')), this.timeoutMs);
+ // Same shape as withQueryDeadline: an un-unref'd timer would hold the loop open for the
+ // rest of its window if the process tried to exit mid-resolve.
+ timeoutId.unref?.();
});
const fetchOptions = (resolveOptions.dispatcher
@@ -150,6 +153,10 @@ export class BaileysVersionResolver {
: undefined) as unknown as RequestInit;
const fetchPromise = b.fetchLatestBaileysVersion(fetchOptions);
+ // Racing abandons the loser without cancelling it. Today that call cannot reject (it catches
+ // everything and resolves the frozen stub), so this is defence against the library changing,
+ // not a live bug: an abandoned rejection would otherwise surface as an unhandled rejection.
+ fetchPromise.catch(() => undefined);
const result = await Promise.race([fetchPromise, timeoutPromise]).finally(() => {
if (timeoutId) clearTimeout(timeoutId);