AOSSIE-Org / AOSSIE-Org/Resonate-Backend

[Bug]: Missing await keywords in Livekit Webhook Room Cleanup

Đang mở
#142 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
JavaScript
Star
43
Fork
120
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

### Description
A critical logic error was identified in the livekit-webhook function. The handler responsible for cleaning up Appwrite room documents after a Livekit session ends is failing to properly synchronize asynchronous calls.

In JavaScript, an async function always returns a Promise. When the code checks if (appwrite.doesRoomExist(...)), it is evaluating a Promise object rather than the boolean result of that promise. Since objects in JavaScript are "truthy," the condition will always pass, potentially attempting to delete rooms that don't exist or failing to wait for the deletion to complete before the function execution context closes

### Location
functions/livekit-webhook/src/main.js

currently
````
if (event.event === 'room_finished') {
const appwriteRoomDocId = event.room.name;

// Bug: doesRoomExist returns a Promise, which is always truthy
log(appwrite.doesRoomExist(appwriteRoomDocId));
if (appwrite.doesRoomExist(appwriteRoomDocId)) {
// Bug: deleteRoom is an async operation but is not awaited
appwrite.deleteRoom(appwriteRoomDocId);
}
}
`````

Impact

- Race Conditions: The function may return a success response to Livekit before the database cleanup actually finishes.
- Unreliable Logging: The log() statement currently logs a Promise { } instead of the actual room status.

### Proposed Fix
Apply the await keyword to ensure the asynchronous database checks and deletions resolve before proceeding

__I would Like to work on this issue__

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.