Skip to content

Commit

Permalink
Fix rare deadlock / stream corruption that could occur
Browse files Browse the repository at this point in the history
  • Loading branch information
Ninjastorm380 committed Mar 8, 2022
1 parent 3220385 commit dc03d7a
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 11 deletions.
12 changes: 7 additions & 5 deletions Maelstrom/Source/Socket/Methods.vb
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,7 @@ Public Partial Class Socket
If Manager.Contains(Index) = False Then _
Throw New ArgumentException("Parameter 'Index' referrs to a non-existent stream!")
SyncLock ReadLock
If Manager.Value(Index).Length >= 16
Return True
Else
If Manager.Value(Index).Length < 16
If NetSocket.Available = 0 then Return False
If WaitForData(16) = False Then Return False
Read(SeekDataHeader, 0, 16)
Expand All @@ -345,14 +343,18 @@ Public Partial Class Socket
Manager.Value(SeekIsMuxed).Write(SeekPaddedData, SeekPaddedLength)
End If
Return (Index = SeekIsMuxed) And Manager.Contains(SeekIsMuxed)
Else
Manager.Value(Index).Read(SeekDataHeader, 16, 0)
UnpackInt32(SeekDataHeader, SeekPaddedLength, 0)
If Manager.Value(Index).Length < 16 + SeekPaddedLength Then Return False Else Return True
End If
End SyncLock
End Function

Private Function WaitForData(Amount as Int32) as Boolean
Dim WaitCounter = 0
Const WaitLimit As Integer = 1 * 1000
Dim WaitGovernor as new Governor(1000)
Const WaitLimit As Integer = 1 * 30
Dim WaitGovernor as new Governor(30)
Do While True
Dim Available as Int32 = NetSocket.Available
If WaitCounter = 0 Then
Expand Down
Binary file modified Maelstrom/bin/Release/netstandard2.0/Maelstrom.dll
Binary file not shown.
Binary file modified Maelstrom/obj/Release/netstandard2.0/Maelstrom.dll
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion Maelstrom/obj/rider.project.restore.info
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16462729035394077
16462738984788879
19 changes: 17 additions & 2 deletions MaelstromTests/TestClient.vb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,24 @@ Friend Class TestClient : Inherits ClientBase
Protected Overrides Sub OnConnectionMain(Socket As Socket)
Dim Governor as new Governor(10)
for x= 0 to P.Length -1
P(x)= {1,1,1,1}
P(x)= {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
Next
for x = 0 to 7
for x = 0 to 199
CreateAsyncInstance(Socket,x)
Next

Expand Down
19 changes: 17 additions & 2 deletions MaelstromTests/TestServer.vb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Friend Class TestServer : Inherits ServerBase

Protected Overrides Sub OnConnectionMain(Socket As Socket)
Dim Governor as new Governor(10)
for x = 0 to 7
for x = 0 to 199
CreateAsyncInstance(Socket,x)
Next
Do While Socket.Connected = True And Online = True
Expand All @@ -27,7 +27,22 @@ Friend Class TestServer : Inherits ServerBase
Protected Overrides Sub OnServerOnline()

for x= 0 to P.Length -1
P(x)= {1,1,1,1}
P(x)= {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
Next
Console.WriteLine("DEBUG - SERVER: server is now online")
End Sub
Expand Down
Binary file modified MaelstromTests/bin/Release/netcoreapp3.1/Maelstrom.dll
Binary file not shown.
Binary file modified MaelstromTests/bin/Release/netcoreapp3.1/MaelstromTests.dll
Binary file not shown.
Binary file modified MaelstromTests/bin/Release/netcoreapp3.1/MaelstromTests.pdb
Binary file not shown.
Binary file modified MaelstromTests/obj/Release/netcoreapp3.1/MaelstromTests.dll
Binary file not shown.
Binary file modified MaelstromTests/obj/Release/netcoreapp3.1/MaelstromTests.pdb
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion MaelstromTests/obj/rider.project.restore.info
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16462729035394077
16462738984788879

0 comments on commit dc03d7a

Please sign in to comment.