惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 三生石上(FineUI控件)
Blog — PlanetScale
Blog — PlanetScale
B
Blog
GbyAI
GbyAI
爱范儿
爱范儿
月光博客
月光博客
N
Netflix TechBlog - Medium
T
Tailwind CSS Blog
G
Google Developers Blog
大猫的无限游戏
大猫的无限游戏
Vercel News
Vercel News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
WordPress大学
WordPress大学
The GitHub Blog
The GitHub Blog
Recent Announcements
Recent Announcements
腾讯CDC
MyScale Blog
MyScale Blog
V
Visual Studio Blog
The Cloudflare Blog
Microsoft Security Blog
Microsoft Security Blog
A
About on SuperTechFans
Google DeepMind News
Google DeepMind News
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(github): cancel gh-read bodies on timeout · openclaw/...
vincentkoc · 2026-06-19 · via Recent Commits to openclaw:main

@@ -43,6 +43,11 @@ type GitHubJsonOptions = {

4343

timeoutMs?: number;

4444

};

454546+

type GitHubBodyReadOptions = {

47+

signal?: AbortSignal;

48+

timeoutPromise?: Promise<never>;

49+

};

50+4651

export function parseRepoArg(args: string[]): string | null {

4752

for (let i = 0; i < args.length; i += 1) {

4853

const arg = args[i];

@@ -174,11 +179,11 @@ function createAppJwt(appId: string, privateKeyPem: string) {

174179

async function withGitHubFetchTimeout<T>(

175180

label: string,

176181

timeoutMs: number,

177-

run: (signal: AbortSignal) => Promise<T>,

182+

run: (signal: AbortSignal, timeoutPromise: Promise<never>) => Promise<T>,

178183

): Promise<T> {

179184

const controller = new AbortController();

180185

let timeout: ReturnType<typeof setTimeout> | undefined;

181-

const timeoutPromise = new Promise<T>((_resolve, reject) => {

186+

const timeoutPromise = new Promise<never>((_resolve, reject) => {

182187

timeout = setTimeout(() => {

183188

const error = new Error(`${label} exceeded timeout of ${timeoutMs}ms`);

184189

reject(error);

@@ -194,9 +199,35 @@ async function withGitHubFetchTimeout<T>(

194199

}

195200

}

196201202+

function cancelReaderSoon(reader: ReadableStreamDefaultReader<Uint8Array>): void {

203+

void Promise.resolve()

204+

.then(() => reader.cancel())

205+

.catch(() => undefined);

206+

}

207+208+

async function readGitHubErrorChunk(

209+

reader: ReadableStreamDefaultReader<Uint8Array>,

210+

timeoutPromise: Promise<never> | undefined,

211+

markCanceled: () => void,

212+

): Promise<ReadableStreamReadResult<Uint8Array>> {

213+

const read = reader.read();

214+

if (!timeoutPromise) {

215+

return await read;

216+

}

217+

return await Promise.race([

218+

read,

219+

timeoutPromise.catch((error: unknown) => {

220+

markCanceled();

221+

cancelReaderSoon(reader);

222+

throw error;

223+

}),

224+

]);

225+

}

226+197227

export async function readBoundedGitHubErrorText(

198228

response: Response,

199229

maxChars = GITHUB_ERROR_BODY_MAX_CHARS,

230+

options: Pick<GitHubBodyReadOptions, "timeoutPromise"> = {},

200231

): Promise<string> {

201232

if (!response.body) {

202233

return "";

@@ -206,10 +237,13 @@ export async function readBoundedGitHubErrorText(

206237

const decoder = new TextDecoder();

207238

let text = "";

208239

let truncated = false;

240+

let canceled = false;

209241210242

try {

211243

while (text.length <= maxChars) {

212-

const { done, value } = await reader.read();

244+

const { done, value } = await readGitHubErrorChunk(reader, options.timeoutPromise, () => {

245+

canceled = true;

246+

});

213247

if (done) {

214248

text += decoder.decode();

215249

break;

@@ -225,7 +259,7 @@ export async function readBoundedGitHubErrorText(

225259

} finally {

226260

if (truncated) {

227261

await reader.cancel().catch(() => undefined);

228-

} else {

262+

} else if (!canceled) {

229263

reader.releaseLock();

230264

}

231265

}

@@ -236,12 +270,15 @@ export async function readBoundedGitHubErrorText(

236270

export async function readBoundedGitHubJson<T>(

237271

response: Response,

238272

maxBytes = GITHUB_JSON_BODY_MAX_BYTES,

273+

options: GitHubBodyReadOptions = {},

239274

): Promise<T> {

240275

const text = await readBoundedResponseText(response, "GitHub API", maxBytes, {

241276

createTooLargeError: (message) =>

242277

Object.assign(new Error(message), {

243278

code: "ETOOBIG",

244279

}),

280+

signal: options.signal,

281+

timeoutPromise: options.timeoutPromise,

245282

});

246283

return JSON.parse(text) as T;

247284

}

@@ -260,7 +297,7 @@ export async function githubJson<T>(

260297

return await withGitHubFetchTimeout(

261298

`GitHub API ${init?.method ?? "GET"} ${path}`,

262299

timeoutMs,

263-

async (signal) => {

300+

async (signal, timeoutPromise) => {

264301

const response = await fetchImpl(`https://api.github.com${path}`, {

265302

method: init?.method ?? "GET",

266303

headers: {

@@ -275,11 +312,11 @@ export async function githubJson<T>(

275312

});

276313277314

if (!response.ok) {

278-

const text = await readBoundedGitHubErrorText(response);

315+

const text = await readBoundedGitHubErrorText(response, undefined, { timeoutPromise });

279316

fail(`${init?.method ?? "GET"} ${path} failed (${response.status}): ${text}`);

280317

}

281318282-

return await readBoundedGitHubJson<T>(response);

319+

return await readBoundedGitHubJson<T>(response, undefined, { signal, timeoutPromise });

283320

},

284321

);

285322

}