mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
fix: panic for non-WS connections to inspector (#11466)
This commit is contained in:
parent
73ed009dda
commit
9b9becf1ae
2 changed files with 33 additions and 1 deletions
|
@ -493,3 +493,29 @@ async fn inspector_json_list() {
|
||||||
assert!(matching_endpoint.is_some());
|
assert!(matching_endpoint.is_some());
|
||||||
child.kill().unwrap();
|
child.kill().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn inspector_connect_non_ws() {
|
||||||
|
// https://github.com/denoland/deno/issues/11449
|
||||||
|
// Verify we don't panic if non-WS connection is being established
|
||||||
|
let script = util::tests_path().join("inspector1.js");
|
||||||
|
let mut child = util::deno_cmd()
|
||||||
|
.arg("run")
|
||||||
|
.arg(inspect_flag_with_unique_port("--inspect"))
|
||||||
|
.arg(script)
|
||||||
|
.stderr(std::process::Stdio::piped())
|
||||||
|
.spawn()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let stderr = child.stderr.as_mut().unwrap();
|
||||||
|
let mut stderr_lines =
|
||||||
|
std::io::BufReader::new(stderr).lines().map(|r| r.unwrap());
|
||||||
|
let mut ws_url = extract_ws_url_from_stderr(&mut stderr_lines);
|
||||||
|
// Change scheme to URL and try send a request. We're not interested
|
||||||
|
// in the request result, just that the process doesn't panic.
|
||||||
|
ws_url.set_scheme("http").unwrap();
|
||||||
|
let resp = reqwest::get(ws_url).await.unwrap();
|
||||||
|
assert_eq!("400 Bad Request", resp.status().to_string());
|
||||||
|
child.kill().unwrap();
|
||||||
|
child.wait().unwrap();
|
||||||
|
}
|
||||||
|
|
|
@ -133,7 +133,13 @@ fn handle_ws_request(
|
||||||
|
|
||||||
if resp.is_ok() {
|
if resp.is_ok() {
|
||||||
tokio::task::spawn_local(async move {
|
tokio::task::spawn_local(async move {
|
||||||
let upgraded = hyper::upgrade::on(req).await.unwrap();
|
let upgrade_result = hyper::upgrade::on(req).await;
|
||||||
|
let upgraded = if let Ok(u) = upgrade_result {
|
||||||
|
u
|
||||||
|
} else {
|
||||||
|
eprintln!("Inspector server failed to upgrade to WS connection");
|
||||||
|
return;
|
||||||
|
};
|
||||||
let websocket =
|
let websocket =
|
||||||
deno_websocket::tokio_tungstenite::WebSocketStream::from_raw_socket(
|
deno_websocket::tokio_tungstenite::WebSocketStream::from_raw_socket(
|
||||||
upgraded,
|
upgraded,
|
||||||
|
|
Loading…
Reference in a new issue