Skip to content

Commit 01c891f

Browse files
committed
服务端心跳检测问题修复
1 parent a07ba5c commit 01c891f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

run/src/main/java/org/wowtools/hppt/run/ss/common/ServerSessionService.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,14 @@ public ServerSessionService(SsConfig ssConfig) {
3535
//起一个线程,定期检查服务心跳
3636
if (ssConfig.heartbeatTimeout > 0) {
3737
Thread.startVirtualThread(() -> {
38+
try {
39+
Thread.sleep(ssConfig.heartbeatTimeout);
40+
} catch (InterruptedException ignored) {
41+
}
3842
while (running) {
3943
long lt = receiver.getLastHeartbeatTime();
40-
if (lt < 0 || System.currentTimeMillis() - lt < ssConfig.heartbeatTimeout) {
44+
if (lt < 0 || System.currentTimeMillis() - lt < ssConfig.heartbeatTimeout * 1.5) {
45+
log.info("心跳检测正常");
4146
try {
4247
Thread.sleep(ssConfig.heartbeatTimeout);
4348
} catch (InterruptedException ignored) {
@@ -130,7 +135,7 @@ public void receiveClientBytes(CTX ctx, byte[] bytes) {
130135
* 当发生难以修复的异常等情况时,主动调用此方法结束当前服务,以便后续自动重启等操作
131136
*/
132137
public void exit(String type) {
133-
log.warn("ServerSessionService exit,type [{}] service {}",type, this);
138+
log.warn("ServerSessionService exit,type [{}] service {}", type, this);
134139
receiver.exit();
135140
try {
136141
onExit();

0 commit comments

Comments
 (0)