-
Notifications
You must be signed in to change notification settings - Fork 61
Description
环境信息
- FISCO BCOS Java SDK 版本: 2.9.1
- FISCO BCOS 节点版本: 2.9.1
- 主机操作系统: Windows 11
- 虚拟机操作系统: Linux (Ubuntu) in VMware Workstation
- VMware 网络模式: 桥接模式 (Bridged Mode)
- Java 版本: JDK 14
- 项目框架: Spring Boot 2.7.6
问题描述
我尝试将一个运行在 Windows 主机上的 Spring Boot 应用,连接到部署在 VMware 虚拟机中的一个4节点 FISCO BCOS 网络。在应用启动过程中,Java SDK 初始化 BcosSDK
时抛出 connection timed out
(连接超时) 异常,导致启动失败。
这个问题在经过了大量的网络故障排查后依旧存在。排查结果表明基础的网络连通性(ICMP 协议)是正常的,但是连接到节点 Channel 端口的 TCP 连接失败。
复现步骤
- 在 Linux 虚拟机中使用
build_chain.sh
脚本搭建一个4节点的 FISCO BCOS 网络。 - 确保所有节点正常运行,并在
0.0.0.0:2020x
上进行监听。 - 将虚拟机的网络适配器设置为 “桥接模式”,并获取其新的局域网 IP 地址(例如
192.168.117.229
)。 - 在 Windows 主机上创建一个标准的 Spring Boot 项目。
- 添加
fisco-bcos-java-sdk:2.9.1
依赖。 - 在
config.toml
配置文件中,填入正确的证书路径和虚拟机的局域网 IP 作为peers
。[network] peers=["192.168.117.229:20200", "192.168.117.229:20201", ...]
- 在 Spring Boot 应用启动时,尝试初始化
BcosSDK
。
期望的行为
BcosSDK
应该成功初始化,并与虚拟机中的节点建立连接。
实际的行为
应用启动失败,抛出 BcosSDKException
异常,其根本原因是 NetworkException
。日志显示对所有配置的节点都出现了 connection timed out
错误。
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2025-10-13 10:10:02.681 ERROR 10776 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fiscoController' defined in file [E:\2025-code\fiscodemo\target\classes\com\fisco\test\controller\FiscoController.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.fisco.test.controller.FiscoController]: Constructor threw exception; nested exception is org.fisco.bcos.sdk.BcosSDKException: create BcosSDK failed, error info: init channel network error!
org.fisco.bcos.sdk.network.NetworkException:
* TRACE INFORMATION:
----------------------------
====> STEP1: try to connect nodes with ecdsa context...
<==== STEP1-1: Load certificates for ecdsa context success...
<==== connect nodes failed, reason:
Failed to connect to all the nodes!
* connect to 192.168.117.229:20200 failed! Please make sure the nodes have been started, and the network between the SDK and the nodes are connected normally.reason: connection timed out: /192.168.117.229:20200
* connect to 192.168.117.229:20201 failed! Please make sure the nodes have been started, and the network between the SDK and the nodes are connected normally.reason: connection timed out: /192.168.117.229:20201
* connect to 192.168.117.229:20202 failed! Please make sure the nodes have been started, and the network between the SDK and the nodes are connected normally.reason: connection timed out: /192.168.117.229:20202
* connect to 192.168.117.229:20203 failed! Please make sure the nodes have been started, and the network between the SDK and the nodes are connected normally.reason: connection timed out: /192.168.117.229:20203
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1334) ~[spring-beans-5.3.24.jar:5.3.24]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1232) ~[spring-beans-5.3.24.jar:5.3.24]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.24.jar:5.3.24]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.24.jar:5.3.24]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.24.jar:5.3.24]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.24.jar:5.3.24]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.24.jar:5.3.24]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.24.jar:5.3.24]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955) ~[spring-beans-5.3.24.jar:5.3.24]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.24.jar:5.3.24]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.24.jar:5.3.24]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[spring-boot-2.7.6.jar:2.7.6]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731) ~[spring-boot-2.7.6.jar:2.7.6]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) ~[spring-boot-2.7.6.jar:2.7.6]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) ~[spring-boot-2.7.6.jar:2.7.6]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303) ~[spring-boot-2.7.6.jar:2.7.6]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292) ~[spring-boot-2.7.6.jar:2.7.6]
at com.fisco.test.FiscodemoApplication.main(FiscodemoApplication.java:10) ~[classes/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.fisco.test.controller.FiscoController]: Constructor threw exception; nested exception is org.fisco.bcos.sdk.BcosSDKException: create BcosSDK failed, error info: init channel network error!
org.fisco.bcos.sdk.network.NetworkException:
* TRACE INFORMATION:
----------------------------
====> STEP1: try to connect nodes with ecdsa context...
<==== STEP1-1: Load certificates for ecdsa context success...
<==== connect nodes failed, reason:
Failed to connect to all the nodes!
* connect to 192.168.117.229:20200 failed! Please make sure the nodes have been started, and the network between the SDK and the nodes are connected normally.reason: connection timed out: /192.168.117.229:20200
* connect to 192.168.117.229:20201 failed! Please make sure the nodes have been started, and the network between the SDK and the nodes are connected normally.reason: connection timed out: /192.168.117.229:20201
* connect to 192.168.117.229:20202 failed! Please make sure the nodes have been started, and the network between the SDK and the nodes are connected normally.reason: connection timed out: /192.168.117.229:20202
* connect to 192.168.117.229:20203 failed! Please make sure the nodes have been started, and the network between the SDK and the nodes are connected normally.reason: connection timed out: /192.168.117.229:20203
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:224) ~[spring-beans-5.3.24.jar:5.3.24]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87) ~[spring-beans-5.3.24.jar:5.3.24]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1326) ~[spring-beans-5.3.24.jar:5.3.24]
... 17 common frames omitted
Caused by: org.fisco.bcos.sdk.BcosSDKException: create BcosSDK failed, error info: init channel network error!
已执行的详尽故障排查
问题的核心似乎在 TCP 协议层。所有常规的配置和网络问题都已被排除:
-
[✅] Ping 测试: Windows 主机可以成功
ping
通虚拟机的 IP 地址 (192.168.117.229
)。 -
[✅] 节点监听: 在虚拟机内部使用
netstat -nlpt
命令,确认fisco-bcos
进程正在0.0.0.0:2020x
上进行LISTEN
。 -
[✅] 虚拟机防火墙: 确认 Linux 虚拟机内的防火墙 (
ufw
) 状态为inactive
(不活动)。 -
[✅] VMware 网络模式: 已将虚拟机网络从 NAT 模式切换到 桥接模式,以确保直接的网络访问,但问题依旧。
-
[✅] 主机杀毒/防火墙: Windows 主机上的所有第三方杀毒和安全软件均已禁用。Windows Defender 防火墙也已为所有网络配置文件完全关闭。
-
[❗️] 关键诊断测试: 在 Windows 主机的 PowerShell 中,对节点的端口进行 TCP 连接测试失败**。这证实了问题并非 Java SDK 特有,而是主机与虚拟机之间一个普遍的 TCP 连接问题。
PS C:\> Test-NetConnection -ComputerName 192.168.117.229 -Port 20200 # 输出: WARNING: TCP connect to (192.168.117.229 : 20200) failed ... PingSucceeded : True TcpTestSucceeded : False
我的问题
鉴于所有导致 connection timed out
的传统原因(主机/客户机防火墙、NAT 问题、节点配置)都已被逐一排除,并且在 ICMP (ping) 成功的情况下,从主机发起的直接 TCP 连接测试仍然失败,这是否可能是一个更深层次的问题?例如与 Windows 网络堆栈、VMware 的桥接驱动程序,或是 Java SDK 使用的 Netty 实现的某个特定需求有关?
请问开发团队是否遇到过类似的在 Windows 主机 -> VMware 虚拟机环境下持续存在的连接问题?任何关于进行更深层次网络诊断的建议都将不胜感激。