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

AsyncJob null ref #926

Closed
xPaw opened this issue Oct 15, 2020 · 1 comment
Closed

AsyncJob null ref #926

xPaw opened this issue Oct 15, 2020 · 1 comment
Labels

Comments

@xPaw
Copy link
Member

xPaw commented Oct 15, 2020

Crash:

04:57:58 [STEAMKIT] SteamDB/TcpConnection: Socket exception occurred while reading packet: System.IO.IOException: Connection lost while reading packet header.
 ---> System.IO.EndOfStreamException: Unable to read beyond the end of the stream.
   at System.IO.BinaryReader.InternalRead(Int32 numBytes)
   at System.IO.BinaryReader.ReadUInt32()
   at SteamKit2.TcpConnection.ReadPacket()
   --- End of inner exception stack trace ---
   at SteamKit2.TcpConnection.ReadPacket()
   at SteamKit2.TcpConnection.NetLoop()
04:57:58 [ERROR] Bootstrapper: Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at SteamKit2.AsyncJob`1.SetFailed(Boolean dueToRemoteFailure)
   at SteamKit2.AsyncJobManager.CancelPendingJobs()
   at SteamKit2.SteamClient.OnClientDisconnected(Boolean userInitiated)
   at SteamKit2.Internal.CMClient.Disconnected(Object sender, DisconnectedEventArgs e)
   at SteamKit2.EnvelopeEncryptedConnection.OnDisconnected(Object sender, DisconnectedEventArgs e)
   at SteamKit2.TcpConnection.Release(Boolean userRequestedDisconnect)
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
   at System.Threading.ThreadHelper.ThreadStart()

@azuisleet's guess is likely correct, in that its a constructor race condition:

06:43 <@azuisleet> ok so I think that is actually a constructor race
06:44 <@azuisleet> the base AsyncJob constructor calls AsyncJobManager.StartJob, registering it into the asyncJobs dictionary
06:45 <@azuisleet> AsyncJob's constructor initializes TaskCompletionSource tcs
06:45 <@azuisleet> but by then, the job is already registered
06:47 <@Netshroud> that seems plausible
06:48 <@azuisleet> TaskCompletionSource could be slow to initalize for example
06:49 <@azuisleet> well, it's a new Task<> so who knows
06:52 <@azuisleet> there's no way the AsyncJob was garbage collected for certain, and tcs is readonly
06:52 <@azuisleet> well, unless ConcurrentDictionary.Values is a weak reference
07:15 <@Netshroud> it doesn't appear to be
07:16 <@Netshroud> it probably is just that plus thread scheduling - just as we're adding it from the base class constructor, something starts enumerating Values to cancel them all, before the subclass constructor is finished

@yaakov-h yaakov-h added the bug label Oct 15, 2020
@azuisleet
Copy link
Member

This should be resolved in cf3f91b.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants