Skip to content

fix(nextcloud-talk): add fetch timeout to message and reaction sends - #48542

Closed
hclsys wants to merge 1 commit into
openclaw:mainfrom
hclsys:fix/nextcloud-talk-send-fetch-timeout
Closed

hclsys wants to merge 1 commit into
openclaw:mainfrom
hclsys:fix/nextcloud-talk-send-fetch-timeout

Conversation

@hclsys

@hclsys hclsys commented Mar 16, 2026

Copy link
Copy Markdown

lobster-biscuit

Problem

sendMessageNextcloudTalk() and sendReactionNextcloudTalk() POST to self-hosted Nextcloud instances with no timeout. A slow or unresponsive server would stall the outbound message pipeline indefinitely.

Self-hosted instances are particularly prone to this since they often lack the CDN-level timeouts that cloud services provide.

Solution

Add a 30-second AbortSignal.timeout to both fetch calls. Both are wrapped in try/catch with { cause: err } to preserve the cause chain.

30 seconds is chosen because outbound sends to self-hosted servers may be slower than typical API metadata calls, but should not take longer than half a minute.

Changes

  • extensions/nextcloud-talk/src/send.ts — add AbortSignal.timeout(30_000) to both sendMessageNextcloudTalk() and sendReactionNextcloudTalk()

Test plan

  • TypeScript compiles
  • oxlint passes
  • Nextcloud Talk send and reaction work end-to-end (requires Nextcloud instance)

🤖 Generated with Claude Code

sendMessageNextcloudTalk() and sendReactionNextcloudTalk() POST to
self-hosted Nextcloud instances with no timeout. A slow or
unresponsive server would stall the outbound message pipeline
indefinitely.

Add a 30-second AbortSignal.timeout to both fetch calls (outbound
sends to self-hosted servers need a longer timeout than API metadata
calls). Both are wrapped in try/catch with { cause: err }.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Signed-off-by: HCL <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added channel: nextcloud-talk Channel integration: nextcloud-talk size: S labels Mar 16, 2026
@greptile-apps

greptile-apps Bot commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a 30-second AbortSignal.timeout to the fetch calls in both sendMessageNextcloudTalk and sendReactionNextcloudTalk, preventing the outbound pipeline from stalling indefinitely against slow or unresponsive self-hosted Nextcloud instances. The implementation is correct: network-level errors are caught and re-thrown with { cause: err } preserved, and all downstream response-body reads (response.text() / response.json()) are already guarded independently so a late-firing signal won't surface as an unhandled rejection.

  • The 30_000 ms timeout value is duplicated across both functions — extracting it as a named module-level constant would make future adjustments a single-line change.
  • Timeout errors (DOMException with name === "TimeoutError") are currently surfaced with the same generic prefix as other fetch failures, making them harder to distinguish in logs; explicitly branching on err.name === "TimeoutError" would improve observability.

Confidence Score: 4/5

  • Safe to merge — the change is narrow, well-scoped, and logically correct with no risk of regressions.
  • The core logic is sound: the signal is applied to the fetch call, body-read error paths are already handled gracefully, and the cause chain is preserved. The only gaps are style-level (duplicated constant, non-specific timeout error message) and do not affect correctness or reliability.
  • No files require special attention beyond the two style suggestions in extensions/nextcloud-talk/src/send.ts.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: extensions/nextcloud-talk/src/send.ts
Line: 115-207

Comment:
**Duplicated magic timeout constant**

The value `30_000` appears in both `sendMessageNextcloudTalk` and `sendReactionNextcloudTalk`. If the timeout needs to be tuned in the future, both sites must be updated in sync. Extracting it as a module-level named constant avoids that drift.

```suggestion
const NEXTCLOUD_TALK_FETCH_TIMEOUT_MS = 30_000;
```

Then replace both occurrences of `AbortSignal.timeout(30_000)` with `AbortSignal.timeout(NEXTCLOUD_TALK_FETCH_TIMEOUT_MS)`.

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: extensions/nextcloud-talk/src/send.ts
Line: 117-122

Comment:
**Timeout errors are not distinguished from other fetch errors**

When `AbortSignal.timeout(30_000)` fires it throws a `DOMException` with `name === "TimeoutError"`. The current catch block wraps every fetch-level error under the same generic message (`"Nextcloud Talk send failed: The operation was aborted due to timeout"`), making it harder for callers or on-call engineers to tell at a glance whether the server was unreachable vs. just slow.

Consider explicitly handling the timeout case:

```suggestion
  } catch (err) {
    if (err instanceof Error && err.name === "TimeoutError") {
      throw new Error(
        `Nextcloud Talk send timed out after ${NEXTCLOUD_TALK_FETCH_TIMEOUT_MS / 1000}s`,
        { cause: err },
      );
    }
    throw new Error(
      `Nextcloud Talk send failed: ${err instanceof Error ? err.message : String(err)}`,
      { cause: err },
    );
  }
```

The same pattern applies to the catch block in `sendReactionNextcloudTalk` (line ~209).

How can I resolve this? If you propose a fix, please make it concise.

Last reviewed commit: 49067bb

Comment on lines 115 to +207
@@ -184,16 +193,25 @@ export async function sendReactionNextcloudTalk(

const url = `${baseUrl}/ocs/v2.php/apps/spreed/api/v1/bot/${normalizedToken}/reaction/${messageId}`;

const 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,
});
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,
signal: AbortSignal.timeout(30_000),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated magic timeout constant

The value 30_000 appears in both sendMessageNextcloudTalk and sendReactionNextcloudTalk. If the timeout needs to be tuned in the future, both sites must be updated in sync. Extracting it as a module-level named constant avoids that drift.

Suggested change
const NEXTCLOUD_TALK_FETCH_TIMEOUT_MS = 30_000;

Then replace both occurrences of AbortSignal.timeout(30_000) with AbortSignal.timeout(NEXTCLOUD_TALK_FETCH_TIMEOUT_MS).

Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/nextcloud-talk/src/send.ts
Line: 115-207

Comment:
**Duplicated magic timeout constant**

The value `30_000` appears in both `sendMessageNextcloudTalk` and `sendReactionNextcloudTalk`. If the timeout needs to be tuned in the future, both sites must be updated in sync. Extracting it as a module-level named constant avoids that drift.

```suggestion
const NEXTCLOUD_TALK_FETCH_TIMEOUT_MS = 30_000;
```

Then replace both occurrences of `AbortSignal.timeout(30_000)` with `AbortSignal.timeout(NEXTCLOUD_TALK_FETCH_TIMEOUT_MS)`.

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +117 to +122
} catch (err) {
throw new Error(
`Nextcloud Talk send failed: ${err instanceof Error ? err.message : String(err)}`,
{ cause: err },
);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Timeout errors are not distinguished from other fetch errors

When AbortSignal.timeout(30_000) fires it throws a DOMException with name === "TimeoutError". The current catch block wraps every fetch-level error under the same generic message ("Nextcloud Talk send failed: The operation was aborted due to timeout"), making it harder for callers or on-call engineers to tell at a glance whether the server was unreachable vs. just slow.

Consider explicitly handling the timeout case:

Suggested change
} catch (err) {
throw new Error(
`Nextcloud Talk send failed: ${err instanceof Error ? err.message : String(err)}`,
{ cause: err },
);
}
} catch (err) {
if (err instanceof Error && err.name === "TimeoutError") {
throw new Error(
`Nextcloud Talk send timed out after ${NEXTCLOUD_TALK_FETCH_TIMEOUT_MS / 1000}s`,
{ cause: err },
);
}
throw new Error(
`Nextcloud Talk send failed: ${err instanceof Error ? err.message : String(err)}`,
{ cause: err },
);
}

The same pattern applies to the catch block in sendReactionNextcloudTalk (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-122

Comment:
**Timeout errors are not distinguished from other fetch errors**

When `AbortSignal.timeout(30_000)` fires it throws a `DOMException` with `name === "TimeoutError"`. The current catch block wraps every fetch-level error under the same generic message (`"Nextcloud Talk send failed: The operation was aborted due to timeout"`), making it harder for callers or on-call engineers to tell at a glance whether the server was unreachable vs. just slow.

Consider explicitly handling the timeout case:

```suggestion
  } catch (err) {
    if (err instanceof Error && err.name === "TimeoutError") {
      throw new Error(
        `Nextcloud Talk send timed out after ${NEXTCLOUD_TALK_FETCH_TIMEOUT_MS / 1000}s`,
        { cause: err },
      );
    }
    throw new Error(
      `Nextcloud Talk send failed: ${err instanceof Error ? err.message : String(err)}`,
      { cause: err },
    );
  }
```

The same pattern applies to the catch block in `sendReactionNextcloudTalk` (line ~209).

How can I resolve this? If you propose a fix, please make it concise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: nextcloud-talk Channel integration: nextcloud-talk size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant