Skip to content

Commit 4d6ca92

Browse files
committed
fix: keep handshake hiccups from killing gateway
1 parent c04a8ca commit 4d6ca92

File tree

2 files changed

+50
-12
lines changed

2 files changed

+50
-12
lines changed

apps/freenet-ping/app/tests/common/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ fn compile_contract(contract_path: &PathBuf) -> anyhow::Result<Vec<u8>> {
309309
&BuildToolConfig {
310310
features: None,
311311
package_type: PackageType::Contract,
312-
debug: true,
312+
debug: false,
313313
},
314314
contract_path,
315315
)?;

crates/core/src/node/network_bridge/p2p_protoc.rs

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -888,12 +888,27 @@ impl P2pConnManager {
888888
.await?;
889889
Ok(EventResult::Continue)
890890
}
891-
Err(handshake_error) => {
892-
tracing::error!(?handshake_error, "Handshake handler error");
893-
Ok(EventResult::Event(
894-
ConnEvent::ClosedChannel(ChannelCloseReason::Handshake).into(),
895-
))
896-
}
891+
Err(handshake_error) => match handshake_error {
892+
HandshakeError::ConnectionClosed(addr) => {
893+
tracing::warn!(
894+
%addr,
895+
"Handshake handler reported connection closed - continuing without shutdown"
896+
);
897+
Ok(EventResult::Continue)
898+
}
899+
HandshakeError::ChannelClosed => {
900+
tracing::warn!(
901+
"Handshake channel reported as closed - treating as transient and continuing"
902+
);
903+
Ok(EventResult::Continue)
904+
}
905+
_ => {
906+
tracing::error!(?handshake_error, "Handshake handler error");
907+
Ok(EventResult::Event(
908+
ConnEvent::ClosedChannel(ChannelCloseReason::Handshake).into(),
909+
))
910+
}
911+
},
897912
}
898913
}
899914
SelectResult::NodeController(msg) => {
@@ -1281,14 +1296,37 @@ impl P2pConnManager {
12811296
let key = (*self.bridge.op_manager.ring.connection_manager.pub_key).clone();
12821297
PeerId::new(self_addr, key)
12831298
};
1284-
timeout(
1299+
let connection_peer_id = peer_id.clone();
1300+
match timeout(
12851301
Duration::from_secs(60),
1286-
cb.send_result(Ok((peer_id, remaining_checks))),
1302+
cb.send_result(Ok((connection_peer_id, remaining_checks))),
12871303
)
12881304
.await
1289-
.inspect_err(|error| {
1290-
tracing::error!("Failed to send connection result: {:?}", error);
1291-
})??;
1305+
{
1306+
Ok(Ok(())) => {}
1307+
Ok(Err(HandshakeError::ChannelClosed)) => {
1308+
tracing::debug!(
1309+
%peer_id,
1310+
"Connection result receiver dropped before completion; treating as benign"
1311+
);
1312+
}
1313+
Ok(Err(e)) => {
1314+
tracing::error!(
1315+
%peer_id,
1316+
error = ?e,
1317+
"Failed to deliver connection result to caller"
1318+
);
1319+
return Err(anyhow::Error::new(e));
1320+
}
1321+
Err(elapsed) => {
1322+
tracing::error!(
1323+
%peer_id,
1324+
elapsed = ?elapsed,
1325+
"Timed out delivering connection result to caller"
1326+
);
1327+
return Err(anyhow::Error::from(elapsed));
1328+
}
1329+
}
12921330
} else {
12931331
tracing::warn!(%peer_id, "No callback for connection established");
12941332
}

0 commit comments

Comments
 (0)