airqo-platform / airqo-platform/AirQo-api

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

未关闭
#4,718 0 条评论 0 个 reaction 已指派 1 人 已被 @Baalmart 认领 在 GitHub 查看
主要语言
JavaScript
星标
26
派生
24
平均合并
5 小时 36 分钟
30 天内合并 PR
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 摘要。