public void DoubleDisposal() { var ms = new MemoryStream(); var reader = new MessagePackStreamReader(ms); reader.Dispose(); reader.Dispose(); }
protected virtual async Task ProcessClient(TcpClient client) { UserCommandType command; ReadOnlySequence <byte>?msgpack; ServiceResult sr = new ServiceResult(); var streamReader = new MessagePackStreamReader(client.GetStream()); while (client.Connected) { command = null; try { msgpack = await streamReader.ReadAsync(_tokenSource.Token).ConfigureAwait(false); if (!msgpack.HasValue) { break; // End of connection } command = MessagePackSerializer.Deserialize <UserCommandType>(msgpack.Value, cancellationToken: _tokenSource.Token); if (command == null) { continue; } LogServerEvent(command); sr.Message = await DataReceived(command).ConfigureAwait(false); if (string.IsNullOrEmpty(sr.Message)) { continue; } await MessagePackSerializer.SerializeAsync <ServiceResult>(client.GetStream(), sr).ConfigureAwait(false); } catch (IOException) { // Client connection failed. Dispose of it break; } catch (Exception e) { if (command != null) { LogDebugEvent(command, e.Message); } else { Console.WriteLine(e); } Console.WriteLine(e); } } streamReader.Dispose(); client.Dispose(); }