mirror of
https://github.com/by-sonic/tglock.git
synced 2026-11-05 23:31:58 +03:00
fix(worker): туннели через Worker рвались с 1003 на новых compatibility date; 2.0.0-beta.16 (#63)
* worker: set binaryType = "arraybuffer" to fix 1003 "binary messages required" Since compatibility date 2026-03-17 Cloudflare delivers binary WebSocket messages as Blob (websocket_standard_binary_type). The message handler accepts only ArrayBuffer and closes every tunnel with 1003. Setting binaryType before accept() restores ArrayBuffer delivery regardless of the compatibility date. * fix(worker): accept Blob frames and name an outdated Worker in the log; 2.0.0-beta.16 Since compatibility date 2026-03-17 Cloudflare delivers binary WebSocket frames as Blob unless binaryType is "arraybuffer", and the Worker closed every tunnel with 1003 right after the handshake. wrangler.toml itself pins 2026-09-19, so every fresh deployment was broken (#58, #50, #53). On top of #61 (binaryType before accept) the Worker now also relays Blob frames in order, and the client log tells the user to redeploy the script when a Worker closes with "1003 binary messages required". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Dmitry Sankevich <16187308+avost@users.noreply.github.com> Co-authored-by: babin <Thartewerner536e@engineer.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+30
-3
@@ -795,9 +795,7 @@ async fn ws_tunnel(
|
||||
});
|
||||
if !received_payload || transport_error {
|
||||
let reason = match frame {
|
||||
Some(frame) => {
|
||||
format!("WebSocket закрыт: {} {}", frame.code, frame.reason)
|
||||
}
|
||||
Some(frame) => describe_ws_close(frame.code.into(), &frame.reason),
|
||||
None => "WebSocket закрыт без ответа Telegram".to_owned(),
|
||||
};
|
||||
return Err(tunnel_route_error(stats, &connected, dc, &reason));
|
||||
@@ -938,6 +936,24 @@ async fn cdn_tcp_tunnel(
|
||||
}
|
||||
}
|
||||
|
||||
/// Текст для журнала, когда WebSocket закрыла другая сторона.
|
||||
///
|
||||
/// `1003 binary messages required` отвечает только старый скрипт Worker'а: с
|
||||
/// compatibility date 2026-03-17 Cloudflare отдаёт бинарные кадры как Blob, и
|
||||
/// такой скрипт рвал каждый туннель сразу после рукопожатия (by-sonic/tglock#61).
|
||||
/// Обновление TGLock код в чужом Cloudflare-аккаунте не меняет, поэтому
|
||||
/// пользователю надо сказать прямо, что делать.
|
||||
fn describe_ws_close(code: u16, reason: &str) -> String {
|
||||
let mut text = format!("WebSocket закрыт: {code} {reason}");
|
||||
if code == 1003 && reason.contains("binary messages required") {
|
||||
text.push_str(
|
||||
" — скрипт Cloudflare Worker устарел: опубликуйте заново \
|
||||
worker/tglock-worker.js из репозитория",
|
||||
);
|
||||
}
|
||||
text
|
||||
}
|
||||
|
||||
fn tunnel_route_error(
|
||||
stats: &Stats,
|
||||
connected: &crate::transport::ConnectedRoute,
|
||||
@@ -969,6 +985,17 @@ mod tests {
|
||||
use tokio_tungstenite::tungstenite::handshake::server::{Request, Response};
|
||||
use tokio_tungstenite::tungstenite::Message;
|
||||
|
||||
#[test]
|
||||
fn an_outdated_worker_close_says_to_redeploy_it() {
|
||||
let outdated = describe_ws_close(1003, "binary messages required");
|
||||
assert!(outdated.starts_with("WebSocket закрыт: 1003 binary messages required"));
|
||||
assert!(outdated.contains("worker/tglock-worker.js"));
|
||||
assert_eq!(
|
||||
describe_ws_close(1011, "Telegram socket failed"),
|
||||
"WebSocket закрыт: 1011 Telegram socket failed"
|
||||
);
|
||||
}
|
||||
|
||||
/// Start the proxy on a kernel-assigned port.
|
||||
///
|
||||
/// Binding first and reading the port back removes the reserve-then-rebind
|
||||
|
||||
Reference in New Issue
Block a user