Repository navigation
Conversation
Both `sendMessageNextcloudTalk()` and `sendReactionNextcloudTalk()` in `extensions/nextcloud-talk/src/send.ts` call `fetch()` without a timeout, so a stalled Nextcloud server can hang the bot process indefinitely. Add `AbortSignal.timeout(30_000)` to both POST calls. Uses 30s (vs 10s for read-only fetches) since message delivery may involve server- side processing. lobster-biscuit Signed-off-by: Chenglun Hu <[email protected]> Signed-off-by: HCL <[email protected]>
Greptile SummaryThis PR adds
Confidence Score: 4/5
Last reviewed commit: 414e7c8 |
| signal: AbortSignal.timeout(30_000), | ||
| }); |
There was a problem hiding this comment.
TimeoutError propagates as raw DOMException
When AbortSignal.timeout() fires, it throws a DOMException with name === 'TimeoutError' rather than an AbortError. Because neither sendMessageNextcloudTalk nor sendReactionNextcloudTalk wraps the fetch() call in a try/catch, callers will receive an opaque DOMException: The operation was aborted due to timeout instead of a descriptive error message.
Consider catching it and re-throwing with a clearer message, consistent with how HTTP error codes are handled below:
let response: Response;
try {
response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
"OCS-APIRequest": "true",
"X-Nextcloud-Talk-Bot-Random": random,
"X-Nextcloud-Talk-Bot-Signature": signature,
},
body: bodyStr,
signal: AbortSignal.timeout(30_000),
});
} catch (err) {
if (err instanceof DOMException && err.name === "TimeoutError") {
throw new Error("Nextcloud Talk send timed out after 30s");
}
throw err;
}The same applies to the sendReactionNextcloudTalk call at line 209.
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/nextcloud-talk/src/send.ts
Line: 117-118
Comment:
**TimeoutError propagates as raw DOMException**
When `AbortSignal.timeout()` fires, it throws a `DOMException` with `name === 'TimeoutError'` rather than an `AbortError`. Because neither `sendMessageNextcloudTalk` nor `sendReactionNextcloudTalk` wraps the `fetch()` call in a try/catch, callers will receive an opaque `DOMException: The operation was aborted due to timeout` instead of a descriptive error message.
Consider catching it and re-throwing with a clearer message, consistent with how HTTP error codes are handled below:
```ts
let response: Response;
try {
response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
"OCS-APIRequest": "true",
"X-Nextcloud-Talk-Bot-Random": random,
"X-Nextcloud-Talk-Bot-Signature": signature,
},
body: bodyStr,
signal: AbortSignal.timeout(30_000),
});
} catch (err) {
if (err instanceof DOMException && err.name === "TimeoutError") {
throw new Error("Nextcloud Talk send timed out after 30s");
}
throw err;
}
```
The same applies to the `sendReactionNextcloudTalk` call at line 209.
How can I resolve this? If you propose a fix, please make it concise.…errors When AbortSignal.timeout fires, the raw DOMException propagates with a cryptic message. Wrap both fetch calls in try/catch to re-throw with a descriptive "Nextcloud Talk send/reaction failed:" prefix, consistent with the existing HTTP error handling in the same functions. Signed-off-by: Chenglun Hu <[email protected]> Signed-off-by: HCL <[email protected]>
Summary
sendMessageNextcloudTalk()andsendReactionNextcloudTalk()inextensions/nextcloud-talk/src/send.tsboth callfetch()without a timeoutAbortSignal.timeout(30_000)to both POST calls (30s for writes vs 10s for reads), consistent with the pattern from fix(tlon): add timeout to SSE client fetch calls (CWE-400) #5926 and fix(telegram): add timeout to file download to prevent DoS (CWE-400) #6914Test plan
lobster-biscuit