Skip to content

Commit

Permalink
Fix NullReferenceException on ChatManager shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberboss committed Oct 5, 2021
1 parent 40a6ad8 commit 19d2d75
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Tgstation.Server.Host/Components/Chat/ChatManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -593,16 +593,20 @@ async Task ProcessMessage(IProvider provider, Message message, CancellationToken
}

// map the channel if it's private and we haven't seen it
var providerChannelId = message.User.Channel.RealId;
KeyValuePair<ulong, ChannelMapping>? mappedChannel;
long providerId;
lock (providers)
{
// important, otherwise we could end up processing during shutdown
cancellationToken.ThrowIfCancellationRequested();

providerId = providers
.Where(x => x.Value == provider)
.Select(x => x.Key)
.First();
mappedChannel = mappedChannels
.Where(x => x.Value.ProviderId == providerId && x.Value.ProviderChannelId == message.User.Channel.RealId)
.Where(x => x.Value.ProviderId == providerId && x.Value.ProviderChannelId == providerChannelId)
.FirstOrDefault();
}

Expand Down Expand Up @@ -648,7 +652,8 @@ await SendMessage(
return;
}

var mapping = mappedChannel.Value.Value;
var mappingNonNullableKvp = mappedChannel.Value;
var mapping = mappingNonNullableKvp.Value;

message.User.Channel.Id = mapping.Channel.Id;
message.User.Channel.Tag = mapping.Channel.Tag;
Expand Down

0 comments on commit 19d2d75

Please sign in to comment.