airqo-platform / airqo-platform/AirQo-api

Bug: NATS broker publishMessage treats synchronous publish() as a Promise

オープン
#4,718 コメント 0 件 リアクション 0 件 担当者 1 名 @Baalmart が担当を希望しています GitHub で見る
主要言語
JavaScript
スター
26
フォーク
24
平均マージ
5時間 36分
マージ済み PR(30日)
81

説明

## Issue Description

In the NATS broker implementation, there's a critical bug in the `publishMessage` method where `client.publish()` is treated as a Promise in a `Promise.race()` construction.

**File:** `src/auth-service/utils/messaging/brokers/nats-broker.js`

**Problem:**
The `@nats/js`'s `publish()` method returns `void` (not a Promise). When treating it as a promise with `Promise.race()`, `publishPromise` resolves immediately as `undefined`, and the timeout branch will always win – raising a false "timed-out" error on every call.

**Impact:**
This will mark the broker as unhealthy and trigger unnecessary fail-over to other message brokers, degrading performance and potentially causing message delivery issues.

## Proposed Solutions

Either:

1. Await the *flush* operation instead:
```js
this.client.publish(topic, payloadBuf);
await this.client.flush();
```

2. Remove the `Promise.race` and rely on the library's internal back-pressure.

## References
- Discovered in PR review: https://github.com/airqo-platform/AirQo-api/pull/4716#discussion_r2051508781

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。