瀏覽代碼

Ensure close on graphite writers on failure or disconnect

Nick Babcock 6 年之前
父節點
當前提交
07c86b54ee
共有 1 個文件被更改,包括 2 次插入1 次删除
  1. 2 1
      OhmGraphite/GraphiteWriter.cs

+ 2 - 1
OhmGraphite/GraphiteWriter.cs

@@ -18,7 +18,7 @@ namespace OhmGraphite
         private readonly string _remoteHost;
         private readonly int _remotePort;
         private readonly bool _tags;
-        private TcpClient _client;
+        private TcpClient _client = new TcpClient();
         private bool _failure = true;
         private static readonly Encoding Utf8NoBom = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true);
 
@@ -38,6 +38,7 @@ namespace OhmGraphite
                 // time connections
                 if (_failure || !_client.Connected)
                 {
+                    _client.Close();
                     _client = new TcpClient();
                     Logger.Debug($"New connection to {_remoteHost}:{_remotePort}");
                     await _client.ConnectAsync(_remoteHost, _remotePort);