From bb56c676c9c100d8619c7714ccae5569fca0c48b Mon Sep 17 00:00:00 2001 From: "Eric P. Nusbaum" Date: Mon, 14 Mar 2022 16:43:42 -0400 Subject: [PATCH] Fix a Race Condition if a disconnect were to happen during processing loop --- MBBSEmu/HostProcess/ExportedModules/ExportedModuleBase.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/MBBSEmu/HostProcess/ExportedModules/ExportedModuleBase.cs b/MBBSEmu/HostProcess/ExportedModules/ExportedModuleBase.cs index 07ef10cb..4529d7ca 100644 --- a/MBBSEmu/HostProcess/ExportedModules/ExportedModuleBase.cs +++ b/MBBSEmu/HostProcess/ExportedModules/ExportedModuleBase.cs @@ -681,7 +681,11 @@ private protected ReadOnlySpan ProcessTextVariables(ReadOnlySpan out var txtvarsFound = _textVariableService.ExtractVariableDefinitions(outputBuffer); - var txtvarDictionary = ChannelDictionary[ChannelNumber].SessionVariables; + //This can happen if a channel disconnects during the processing of the main loop + if (!ChannelDictionary.TryGetValue(ChannelNumber, out var channelSession)) + return outputBuffer; + + var txtvarDictionary = channelSession.SessionVariables; //Get Their Values var txtvarMemoryBase = Module.Memory.GetVariablePointer("TXTVARS");