fix: load balancer panics, stealth flag, shadow DOM polyfill
Fixes #1: replace unwrap() panics in run_multi_worker_serve with match on the Result. Fixes #2: route /json round-robin via worker_port instead of hardcoded port+1. Fixes #3: return 502 Bad Gateway when a worker is unreachable instead of silently dropping the connection. Fixes #5: thread --stealth through start_with_options -> CdpContext -> BrowserContext::with_options so the flag actually has an effect in serve mode (was let _ before). Log message now reflects the actual capability based on the stealth cargo feature being compiled in. Fixes #15: try/catch the parentNode assignment in the attachShadow polyfill so it doesn't throw a TypeError against the read-only Node.parentNode getter (Cloudflare Turnstile triggers this path).
This commit is contained in:
1 parent
74cf88d0f4
commit
99e75f1e62
4 files changed
+106
-24
No files matched your search
@@ -139,15 +139,19 @@ async fn main() -> anyhow::Result<()> {
|
||||
tracing::info!("User-Agent: {}", ua);
|
||||
}
|
||||
if stealth {
|
||||
tracing::info!("Stealth mode enabled (TLS fingerprint spoofing)");
|
||||
#[cfg(feature = "stealth")]
|
||||
tracing::info!(
|
||||
"Stealth mode enabled (TLS fingerprint impersonation + tracker blocking)"
|
||||
);
|
||||
#[cfg(not(feature = "stealth"))]
|
||||
tracing::info!("Stealth mode enabled (tracker blocking)");
|
||||
}
|
||||
let _ = stealth;
|
||||
|
||||
if workers > 1 {
|
||||
tracing::info!("{} worker processes", workers);
|
||||
run_multi_worker_serve(port, workers, proxy, stealth).await?;
|
||||
} else {
|
||||
obscura_cdp::start_with_options(port, proxy).await?;
|
||||
obscura_cdp::start_with_options(port, proxy, stealth).await?;
|
||||
}
|
||||
}
|
||||
Some(Command::Fetch { url, dump, selector, wait, wait_until, user_agent, stealth, eval, quiet }) => {
|
||||
@@ -161,7 +165,7 @@ async fn main() -> anyhow::Result<()> {
|
||||
if let Some(ref proxy) = args.proxy {
|
||||
tracing::info!("Using proxy: {}", proxy);
|
||||
}
|
||||
obscura_cdp::start_with_options(args.port, args.proxy).await?;
|
||||
obscura_cdp::start_with_options(args.port, args.proxy, false).await?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,11 +226,49 @@ async fn run_multi_worker_serve(
|
||||
let request_line = String::from_utf8_lossy(&full_peek[..n]);
|
||||
|
||||
if request_line.contains("/json") {
|
||||
let worker_addr = format!("127.0.0.1:{}", port + 1);
|
||||
if let Ok(mut worker_stream) = tokio::net::TcpStream::connect(&worker_addr).await {
|
||||
tokio::spawn(async move {
|
||||
let _ = tokio::io::copy_bidirectional(&mut tokio::net::TcpStream::from_std(client_stream.into_std().unwrap()).unwrap(), &mut worker_stream).await;
|
||||
});
|
||||
let worker_addr = format!("127.0.0.1:{}", worker_port);
|
||||
match tokio::net::TcpStream::connect(&worker_addr).await {
|
||||
Ok(mut worker_stream) => {
|
||||
tokio::spawn(async move {
|
||||
let std_stream = match client_stream.into_std() {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
tracing::error!(
|
||||
"/json: failed to convert client to std stream: {}",
|
||||
e
|
||||
);
|
||||
return;
|
||||
}
|
||||
};
|
||||
let mut client = match tokio::net::TcpStream::from_std(std_stream) {
|
||||
Ok(c) => c,
|
||||
Err(e) => {
|
||||
tracing::error!(
|
||||
"/json: failed to recreate tokio TcpStream: {}",
|
||||
e
|
||||
);
|
||||
return;
|
||||
}
|
||||
};
|
||||
let _ = tokio::io::copy_bidirectional(
|
||||
&mut client,
|
||||
&mut worker_stream,
|
||||
)
|
||||
.await;
|
||||
});
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::warn!("/json worker {} unreachable: {}", worker_addr, e);
|
||||
tokio::spawn(async move {
|
||||
let mut s = client_stream;
|
||||
let _ = s
|
||||
.write_all(
|
||||
b"HTTP/1.1 502 Bad Gateway\r\nConnection: close\r\n\r\n",
|
||||
)
|
||||
.await;
|
||||
let _ = s.shutdown().await;
|
||||
});
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -234,9 +276,20 @@ async fn run_multi_worker_serve(
|
||||
|
||||
let worker_addr = format!("127.0.0.1:{}", worker_port);
|
||||
tokio::spawn(async move {
|
||||
if let Ok(mut worker_stream) = tokio::net::TcpStream::connect(&worker_addr).await {
|
||||
let mut client = client_stream;
|
||||
let _ = tokio::io::copy_bidirectional(&mut client, &mut worker_stream).await;
|
||||
match tokio::net::TcpStream::connect(&worker_addr).await {
|
||||
Ok(mut worker_stream) => {
|
||||
let mut client = client_stream;
|
||||
let _ =
|
||||
tokio::io::copy_bidirectional(&mut client, &mut worker_stream).await;
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::warn!("worker {} unreachable: {}", worker_addr, e);
|
||||
let mut s = client_stream;
|
||||
let _ = s
|
||||
.write_all(b"HTTP/1.1 502 Bad Gateway\r\nConnection: close\r\n\r\n")
|
||||
.await;
|
||||
let _ = s.shutdown().await;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -654,4 +707,4 @@ fn dump_links(page: &Page) {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user