Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

死锁问题 #463

Open
TCL606 opened this issue Apr 28, 2023 · 7 comments
Open

死锁问题 #463

TCL606 opened this issue Apr 28, 2023 · 7 comments
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed question Further information is requested

Comments

@TCL606
Copy link
Member

TCL606 commented Apr 28, 2023

Describe the bug
Server 中存在潜在的死锁问题

To Reproduce
暂不清楚,但服务器上的确观察到此现象
微信图片_20230428224550

Desktop (please complete the following information):
Ubuntu 22.04

Additional context
死锁问题是非常严重的,将直接导致比赛不能正常进行。欢迎大家讨论一下当前死锁问题的原因,解决这个问题。以及如果发现了复现该问题的方式,可以在本 issue 中提出。

@TCL606 TCL606 added the bug Something isn't working label Apr 28, 2023
@TCL606
Copy link
Member Author

TCL606 commented Apr 29, 2023

现在基本确定死锁问题由逻辑内部引起(因为在服务器上发现了没有观战者但是死锁的容器)。初步看了一下逻辑,发现了几点会导致死锁的地方:

在 ChangePlayerState 中,连续两次对 gameObjLock 上锁(在 gameObjLock 被锁时修改 IsMoving)

public void ChangePlayerState(PlayerStateType value = PlayerStateType.Null, GameObj? gameObj = null)
{
lock (gameObjLock)
{
++threadNum;
whatInteractingWith = gameObj;
if (value != PlayerStateType.Moving)
IsMoving = false;
playerState = (value == PlayerStateType.Moving) ? PlayerStateType.Null : value;
//Debugger.Output(this,playerState.ToString()+" "+IsMoving.ToString());
}
}

另一个问题 是 MoveLock 和 gameObjLock 的死锁问题。比如,这里用 MoveLock 加锁了,而 ChangePlayerState 中对 gameObjLock 加锁,即在这里用 MoveLock 锁 gameObjLock

lock (player.MoveLock)
{
switch (player.PlayerState)
{
case PlayerStateType.OpeningTheChest:
((Chest)player.WhatInteractingWith).StopOpen();
player.ChangePlayerState(value, gameObj);
break;

public void ChangePlayerState(PlayerStateType value = PlayerStateType.Null, GameObj? gameObj = null)
{
lock (gameObjLock)
{
++threadNum;
whatInteractingWith = gameObj;
if (value != PlayerStateType.Moving)
IsMoving = false;
playerState = (value == PlayerStateType.Moving) ? PlayerStateType.Null : value;
//Debugger.Output(this,playerState.ToString()+" "+IsMoving.ToString());
}
}

但在 MoveEngine 中又用 MoveLock 锁 gameObjLock

lock (obj.MoveLock)
obj.IsMoving = true;

lock (obj.MoveLock)
obj.IsMoving = false; // 结束移动

这些地方都有可能导致死锁

@Timothy-Liuxf
Copy link
Member

Timothy-Liuxf commented Apr 29, 2023

@TCL606 我记得 C# 锁是可重入的,持有锁的线程可以再次加锁来着;
另外这个“另一个问题”里,两处都是 MoveLock 锁 gameObjLock,好像没啥问题?(没太仔细看代码,单纯看了 clgg 的叙述)

@TCL606
Copy link
Member Author

TCL606 commented Apr 29, 2023

@TCL606 我记得 C# 锁是可重入的,持有锁的线程可以再次加锁来着; 另外这个“另一个问题”里,两处都是 MoveLock 锁 gameObjLock,好像没啥问题?(没太仔细看代码,单纯看了 clgg 的叙述)

确实,看错了

@Timothy-Liuxf Timothy-Liuxf added help wanted Extra attention is needed question Further information is requested labels Apr 30, 2023
@TCL606
Copy link
Member Author

TCL606 commented May 26, 2023

鸵鸟算法成功了,死锁暂时没有发现过了

@TCL606 TCL606 closed this as completed May 26, 2023
@Timothy-Liuxf
Copy link
Member

Timothy-Liuxf commented May 26, 2023

鸵鸟算法成功了,死锁暂时没有发现过了

???STM 鸵鸟算法

@TCL606
Copy link
Member Author

TCL606 commented May 26, 2023

又发现死锁辣!

@TCL606 TCL606 reopened this May 26, 2023
@Timothy-Liuxf
Copy link
Member

又发现死锁辣!

哈哈哈哈哈哈哈哈哈哈🤣🤣🤣

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants