mirror of
https://github.com/quasar/Quasar.git
synced 2026-04-25 07:15:59 +03:00
[GH-ISSUE #1230] SafeSendMessage BUG!! #907
Labels
No labels
bug
bug
cant-reproduce
discussion
duplicate
easy
enhancement
help wanted
improvement
invalid
need more info
pull-request
question
wont-add
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/Quasar#907
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @AlphaCharry on GitHub (Dec 26, 2023).
Original GitHub issue: https://github.com/quasar/Quasar/issues/1230
Quasar version
1.4.0
Server installed .NET version
.NET 4.5.2
Server operating system
Windows 10/Server 2019/2016
Client installed .NET version
.NET 4.5.2
Client operating system
Windows 11/Server 2022
Build configuration
Debug
Describe the bug
Quasar.exe Framework V: v4.0.30319 Bug:
"The process terminated due to an unhandled exception. Exception information:".
System.ObjectDisposedException
System.Runtime.InteropServices.SafeHandle.DangerousAddRef(Boolean ByRef) System.StubHelpers.StubHelpers.SafeHandleAddRef(System.Runtime.InteropServices.SafeHandle, Boolean ByRef) Microsoft.Win32.Win32Native.ReleaseMutex(Microsoft.Win32.SafeHandles.SafeWaitHandle) System.Threading.Mutex.ReleaseMutex()
Quasar.Server.Networking.Client.SafeSendMessage(Quasar.Common.Messages.IMessage) Quasar.Server.Networking.Client.ProcessSendBuffers(System.Object) System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() System.Threading.ThreadPoolWorkQueue.Dispatch()
How to reproduce
C# Code
Open multiple remote control Shell, and when the client may be unstable, the client will return data, and an accident occurs at this time.
Expected behavior
private void SafeSendMessage(IMessage message)
{
if (_stream == null || !_stream.CanWrite)
{
return;
}
}
Actual behavior
"It crashes directly, check the error in the Windows log
Additional context
private void SafeSendMessage(IMessage message)
{
if (_stream == null || !_stream.CanWrite)
{
return;
}
}
this ismy code fix
@AlphaCharry commented on GitHub (Dec 26, 2023):
This exception is System.ObjectDisposedException, which usually occurs when trying to access an object that has already been disposed. In this case, the exception occurs in the System.Threading.Mutex.ReleaseMutex() method, which means you may be trying to release a mutex that has already been released. In the code you provided, _singleWriteMutex.ReleaseMutex() is called in the finally block, which means it will be executed whether or not the code in the try block throws an exception. If _singleWriteMutex is released before the finally block is executed, then when the finally block tries to release it, it will throw an ObjectDisposedException. To solve this problem, you need to ensure that _singleWriteMutex is not released before the finally block is executed. You can do this by checking if _singleWriteMutex is null or has already been released. Here is a possible solution:
@MaxXor commented on GitHub (Dec 26, 2023):
Can you create a PR with the fix?
@AlphaCharry commented on GitHub (Dec 26, 2023):
What's PR?
@MaxXor commented on GitHub (Dec 26, 2023):
A pull request: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request