linux - 即使客户端认为连接已经建立,TcpListener 也会卡在 accept() 中
问题描述
let addr: SocketAddr = self.listen_bind.parse().unwrap();
let mut listener = TcpListener::bind(&addr).await?;
info!("Nightfort listening on {}", addr);
loop {
info!("debug1");
match listener.accept().await {
Ok((stream, addr)) => {
info!("debug2");
let watcher = self.watcher.clone();
info!("debug3");
tokio::spawn(async move {
info!("debug4");
if let Err(e) = Nightfort::process(watcher, stream, addr).await {
error!("Error on this ranger: {}, error: {:?}", addr, e);
}
});
}
Err(e) => error!("Socket conn error {}", e),
}
// let (stream, addr) = listener.accept().await?;
}
我花了两天时间解决这个奇怪的问题。rust中的进程在我本地的macos,linux,linux上的docker上可以很好的运行,但是在aws linux或者aws上的k8s上就不能运行了。我发现的主要问题是:accept()
即使客户端认为它建立了与服务器的连接并开始向它发送消息,进程也会挂起。ps
显示服务器进程处于S
状态。代码是用 alpha 库在 nightly rust 中编写的,我认为依赖项中可能存在错误,然后我更新了我的代码并使用最新版本的依赖项将其切换为 stable rust,但问题仍然存在。
解决方案
推荐阅读
- java - IllegalStateException:会话/EntityManager 已关闭
- javascript - 从一个孩子到另一个孩子反应道具
- java - JsonFormat 的模式选项的常量
- typescript - 是否可以从其泛型类型自动生成类属性?
- php - 如何在 guzzle 响应中获取身份验证并发送到视图
- sql - 在 where 子句中使用 CASE 表达式
- cdi - Quarkus / CDI 和“java config”DI 定义
- asp.net-core - 如何使用 devexpress blazor 实现此网格的内联编辑
- java - 如何使用 Mockito FrameWork 模拟 mongoTemplate 对象?
- c# - 单击另一个复选框时禁用一个复选框