跳到主内容
@wquguru
精选85Cloudflare Workers(Changelog)语言与库

Cloudflare Workers 11月17日起默认启用 request.signal

Workers - Request.signal will be enabled by default in Workers on November 17

原文
发到 X
推荐理由

破坏性变更:11月17日后兼容性日期的Worker默认行为改变,可能影响未显式处理signal的现有逻辑,建议检查并适配。

Starting November 17, 2026, Workers with a compatibility date of 2026-11-17 or later will receive client disconnection events through request.signal by default. Use these events to stop unnecessary work when a client leaves. You will no longer need the enable_request_signal compatibility flag for these dates.

自 2026 年 11 月 17 日起,兼容性日期为 2026-11-17 或之后的 Workers 将默认通过 request.signal 接收客户端断开连接事件。利用这些事件可以在客户端离开时停止不必要的工作。对于这些日期,您将不再需要 enable_request_signal 兼容性标志。

We introduced this feature in May 2025. You can log cancellations, clean up resources, or cancel operations that accept an AbortSignal.

我们在 2025 年 5 月引入了此功能。您可以记录取消操作、清理资源或取消接受 AbortSignal 的操作。

For example, this Worker logs a client disconnection and cancels an outgoing request:

例如,此 Worker 会记录客户端断开连接并取消出站请求:

src/index.jsjs

src/index.js

代码 · 14 行
export default {
	async fetch(request) {
		request.signal.addEventListener(
			"abort",
			() => {
				console.log("Client disconnected");
			},
			{ once: true },
		);
		return fetch("https://example.com/slow-response", {
			signal: request.signal,
		});
	},
};

src/index.tsts

src/index.ts

代码 · 14 行
export default {
	async fetch(request): Promise<Response> {
		request.signal.addEventListener(
			"abort",
			() => {
				console.log("Client disconnected");
			},
			{ once: true },
		);
		return fetch("https://example.com/slow-response", {
			signal: request.signal,
		});
	},
} satisfies ExportedHandler;

Existing Workers keep their current behavior until you change their compatibility date or flags. To try this feature before November 17, keep your current date and add enable_request_signal to your compatibility flags.

现有的 Workers 在更改其兼容性日期或标志之前将保持当前行为。要在 11 月 17 日之前试用此功能,请保留当前日期并在兼容性标志中添加 enable_request_signal。

With a compatibility date of 2026-11-17 or later, add disable_request_signal to opt out. This change does not enable request_signal_passthrough. Pass the signal explicitly, as the example does.

对于兼容性日期为 2026-11-17 或之后的情况,添加 disable_request_signal 以选择退出。此更改不会启用 request_signal_passthrough。请像示例中那样显式传递 signal。

For more information, refer to the Request API and the Request.signal compatibility flag.

更多信息,请参阅 Request API 和 Request.signal 兼容性标志。

更进一步:量化金融体系

看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力

进入量化体系 →

相似阅读

关联信息,但可能不是同一事件