{"action":"created","issue":{"url":"https://api.github.com/repos/NLog/NLog/issues/1058","labels_url":"https://api.github.com/repos/NLog/NLog/issues/1058/labels{/name}","comments_url":"https://api.github.com/repos/NLog/NLog/issues/1058/comments","events_url":"https://api.github.com/repos/NLog/NLog/issues/1058/events","html_url":"https://github.com/NLog/NLog/issues/1058","id":118255394,"number":1058,"title":"Deadlock in NetworkTarget ","user":{"login":"mikhail-barg","id":2208971,"avatar_url":"https://avatars.githubusercontent.com/u/2208971?v=3","gravatar_id":"","url":"https://api.github.com/users/mikhail-barg","html_url":"https://github.com/mikhail-barg","followers_url":"https://api.github.com/users/mikhail-barg/followers","following_url":"https://api.github.com/users/mikhail-barg/following{/other_user}","gists_url":"https://api.github.com/users/mikhail-barg/gists{/gist_id}","starred_url":"https://api.github.com/users/mikhail-barg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikhail-barg/subscriptions","organizations_url":"https://api.github.com/users/mikhail-barg/orgs","repos_url":"https://api.github.com/users/mikhail-barg/repos","events_url":"https://api.github.com/users/mikhail-barg/events{/privacy}","received_events_url":"https://api.github.com/users/mikhail-barg/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/NLog/NLog/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/NLog/NLog/labels/network-target","name":"network-target","color":"ffffff"},{"url":"https://api.github.com/repos/NLog/NLog/labels/up-for-grabs","name":"up-for-grabs","color":"5319e7"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/NLog/NLog/milestones/14","html_url":"https://github.com/NLog/NLog/milestones/4.3","labels_url":"https://api.github.com/repos/NLog/NLog/milestones/14/labels","id":1369256,"number":14,"title":"4.3","description":"","creator":{"login":"304NotModified","id":5808377,"avatar_url":"https://avatars.githubusercontent.com/u/5808377?v=3","gravatar_id":"","url":"https://api.github.com/users/304NotModified","html_url":"https://github.com/304NotModified","followers_url":"https://api.github.com/users/304NotModified/followers","following_url":"https://api.github.com/users/304NotModified/following{/other_user}","gists_url":"https://api.github.com/users/304NotModified/gists{/gist_id}","starred_url":"https://api.github.com/users/304NotModified/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/304NotModified/subscriptions","organizations_url":"https://api.github.com/users/304NotModified/orgs","repos_url":"https://api.github.com/users/304NotModified/repos","events_url":"https://api.github.com/users/304NotModified/events{/privacy}","received_events_url":"https://api.github.com/users/304NotModified/received_events","type":"User","site_admin":false},"open_issues":22,"closed_issues":13,"state":"open","created_at":"2015-10-21T22:23:20Z","updated_at":"2015-12-20T22:41:32Z","due_on":"2016-01-09T23:00:00Z","closed_at":null},"comments":4,"created_at":"2015-11-22T10:37:35Z","updated_at":"2015-12-23T13:42:50Z","closed_at":null,"body":"This issue was initially found during testing of #902. I'm reposting it as a separate issue.\r\n\r\nWhat we have noticed though is some deadlock condition happening both with previous and curent code. The setup is like following:\r\n\r\nconfig:\r\n```xml\r\n      <target xsi:type=\"Network\"\r\n        onOverflow=\"Discard\"\r\n        newLine=\"true\"\r\n        layout=\"${msg4Json}\"\r\n        encoding=\"utf-8\"\r\n        connectionCacheSize=\"5\"\r\n        keepConnection=\"false\"\r\n        address=\"tcp://logstash.our_local_host_name.com:9002\"\r\n              name=\"network\"\r\n      />\r\n```\r\n\r\ntest program\r\n```c#\r\n        static void Main(string[] args)\r\n        {\r\n            Logger logger = LogManager.GetCurrentClassLogger();\r\n            for (int i = 0; i < 100000; ++i)\r\n            {\r\n                logger.Trace(\"log \" + i);\r\n            };\r\n            Console.WriteLine(\"Done\");\r\n            Console.Read();\r\n        }\r\n```\r\n\r\nCall stacks at the moment of deadlock for the 4.2.0:\r\n```\r\nWorker thread:\r\n>\tNLog.dll!NLog.Targets.NetworkTarget.Write.AnonymousMethod__a(System.Exception ex) + 0x76 bytes\t\r\n \tNLog.dll!NLog.Targets.NetworkTarget.ChunkedSend.AnonymousMethod__1a(System.Exception ex) + 0x74 bytes\t\r\n \tNLog.dll!NLog.Internal.NetworkSenders.TcpNetworkSender.ProcessNextQueuedItem() + 0x10c bytes\t\r\n \tNLog.dll!NLog.Internal.NetworkSenders.TcpNetworkSender.SocketOperationCompleted(object sender, System.Net.Sockets.SocketAsyncEventArgs e) + 0x1ad bytes\t\r\n \tmscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0x285 bytes\t\r\n \tmscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0x9 bytes\t\r\n \tmscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x57 bytes\t\r\n \tSystem.dll!System.Net.Sockets.SocketAsyncEventArgs.FinishOperationAsyncFailure(System.Net.Sockets.SocketError socketError, int bytesTransferred, System.Net.Sockets.SocketFlags flags) + 0xa6 bytes\t\r\n \tSystem.dll!System.Net.Sockets.SocketAsyncEventArgs.CompletionPortCallback(uint errorCode, uint numBytes, System.Threading.NativeOverlapped* nativeOverlapped) + 0xa8 bytes\t\r\n \tmscorlib.dll!System.Threading._IOCompletionCallback.PerformIOCompletionCallback(uint errorCode, uint numBytes, System.Threading.NativeOverlapped* pOVERLAP) + 0x96 bytes\t\r\n \t[Native to Managed Transition]\t\r\n\r\nMain thread: \r\n> \tNLog.dll!NLog.Internal.NetworkSenders.TcpNetworkSender.ProcessNextQueuedItem() + 0x64 bytes\t\r\n\tNLog.dll!NLog.Internal.NetworkSenders.TcpNetworkSender.DoSend(byte[] bytes, int offset, int length, NLog.Common.AsyncContinuation asyncContinuation) + 0x1f4 bytes\t\r\n \tNLog.dll!NLog.Internal.NetworkSenders.NetworkSender.Send(byte[] bytes, int offset, int length, NLog.Common.AsyncContinuation asyncContinuation) + 0x82 bytes\t\r\n \tNLog.dll!NLog.Targets.NetworkTarget.ChunkedSend.AnonymousMethod__1a(System.Exception ex) + 0x38c bytes\t\r\n \tNLog.dll!NLog.Targets.NetworkTarget.ChunkedSend(NLog.Internal.NetworkSenders.NetworkSender sender, byte[] buffer, NLog.Common.AsyncContinuation continuation) + 0x15b bytes\t\r\n \tNLog.dll!NLog.Targets.NetworkTarget.Write(NLog.Common.AsyncLogEventInfo logEvent) + 0x469 bytes\t\r\n \tNLog.dll!NLog.Targets.Target.WriteAsyncLogEvent(NLog.Common.AsyncLogEventInfo logEvent) + 0x1a4 bytes\t\r\n \tNLog.dll!NLog.LoggerImpl.WriteToTargetWithFilterChain(NLog.Internal.TargetWithFilterChain targetListHead, NLog.LogEventInfo logEvent, NLog.Common.AsyncContinuation onException) + 0x229 bytes\t\r\n \tNLog.dll!NLog.LoggerImpl.Write(System.Type loggerType, NLog.Internal.TargetWithFilterChain targets, NLog.LogEventInfo logEvent, NLog.LogFactory factory) + 0x23c bytes\t\r\n \tNLog.dll!NLog.Logger.WriteToTargets(NLog.LogLevel level, System.IFormatProvider formatProvider, string message) + 0xf9 bytes\t\r\n \tNLog.dll!NLog.Logger.Trace(string message) + 0x59 bytes\t\r\n \tNlogConsoleTest.exe!NlogConsoleTest.Program.Main(string[] args) Line 19 + 0x68 bytes\tC#\r\n```\r\n\r\ncall stacks at the moment of deadlock for the 4.2.1:\r\n```\r\nWorker thread:\r\n \tmscorlib.dll!System.Threading.Monitor.Enter(object obj, ref bool lockTaken) + 0x17 bytes\t\r\n>\tNLog.dll!NLog.Targets.NetworkTarget.Write.AnonymousMethod__a(System.Exception ex) Line 321 + 0x1a bytes\tC#\r\n \tNLog.dll!NLog.Targets.NetworkTarget.ChunkedSend.AnonymousMethod__19(System.Exception ex) Line 485 + 0x10 bytes\tC#\r\n \tNLog.dll!NLog.Internal.NetworkSenders.TcpNetworkSender.SocketOperationCompleted(object sender, System.Net.Sockets.SocketAsyncEventArgs e) Line 216 + 0x11 bytes\tC#\r\n \tSystem.dll!System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(System.Net.Sockets.SocketAsyncEventArgs e) + 0x15 bytes\t\r\n \tSystem.dll!System.Net.Sockets.SocketAsyncEventArgs.ExecutionCallback(object ignored) + 0xf bytes\t\r\n \tmscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0xa7 bytes\t\r\n \tmscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0x16 bytes\t\r\n \tmscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x41 bytes\t\r\n \tSystem.dll!System.Net.Sockets.SocketAsyncEventArgs.FinishOperationSuccess(System.Net.Sockets.SocketError socketError, int bytesTransferred, System.Net.Sockets.SocketFlags flags) + 0x77e bytes\t\r\n \tSystem.dll!System.Net.Sockets.SocketAsyncEventArgs.CompletionPortCallback(uint errorCode, uint numBytes, System.Threading.NativeOverlapped* nativeOverlapped) + 0x37 bytes\t\r\n \tmscorlib.dll!System.Threading._IOCompletionCallback.PerformIOCompletionCallback(uint errorCode, uint numBytes, System.Threading.NativeOverlapped* pOVERLAP) + 0x6e bytes\t\r\n \t[Native to Managed Transition]\t\r\n\r\nMain thread:\r\n \tmscorlib.dll!System.Threading.Monitor.Enter(object obj, ref bool lockTaken) + 0x17 bytes\t\r\n>\tNLog.dll!NLog.Internal.NetworkSenders.TcpNetworkSender.ProcessNextQueuedItem() Line 227 + 0x11 bytes\tC#\r\n \tNLog.dll!NLog.Internal.NetworkSenders.TcpNetworkSender.DoSend(byte[] bytes, int offset, int length, NLog.Common.AsyncContinuation asyncContinuation) Line 172 + 0x8 bytes\tC#\r\n \tNLog.dll!NLog.Internal.NetworkSenders.NetworkSender.Send(byte[] bytes, int offset, int length, NLog.Common.AsyncContinuation asyncContinuation) Line 115 + 0x16 bytes\tC#\r\n \tNLog.dll!NLog.Targets.NetworkTarget.ChunkedSend.AnonymousMethod__19(System.Exception ex) Line 511 + 0x37 bytes\tC#\r\n \tNLog.dll!NLog.Targets.NetworkTarget.ChunkedSend(NLog.Internal.NetworkSenders.NetworkSender sender, byte[] buffer, NLog.Common.AsyncContinuation continuation) Line 514 + 0x10 bytes\tC#\r\n \tNLog.dll!NLog.Targets.NetworkTarget.Write(NLog.Common.AsyncLogEventInfo logEvent) Line 316 + 0x47 bytes\tC#\r\n \tNLog.dll!NLog.Targets.Target.WriteAsyncLogEvent(NLog.Common.AsyncLogEventInfo logEvent) Line 204 + 0x34 bytes\tC#\r\n \tNLog.dll!NLog.LoggerImpl.WriteToTargetWithFilterChain(NLog.Internal.TargetWithFilterChain targetListHead, NLog.LogEventInfo logEvent, NLog.Common.AsyncContinuation onException) Line 196 + 0x28 bytes\tC#\r\n \tNLog.dll!NLog.LoggerImpl.Write(System.Type loggerType, NLog.Internal.TargetWithFilterChain targets, NLog.LogEventInfo logEvent, NLog.LogFactory factory) Line 99 + 0xe bytes\tC#\r\n \tNLog.dll!NLog.Logger.WriteToTargets(NLog.LogLevel level, System.IFormatProvider formatProvider, string message) Line 542 + 0x41 bytes\tC#\r\n \tNLog.dll!NLog.Logger.Trace(string message) Line 183 + 0x13 bytes\tC#\r\n \tTEST.exe!TEST.Program.Main(string[] args) Line 18 + 0x46 bytes\tC#\r\n \t[Native to Managed Transition]\t\r\n \t[Managed to Native Transition]\t\r\n \tmscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args) + 0x6b bytes\t\r\n \tMicrosoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() + 0x27 bytes\t\r\n \tmscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) + 0x6f bytes\t\r\n \tmscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0xa7 bytes\t\r\n \tmscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0x16 bytes\t\r\n \tmscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x41 bytes\t\r\n \tmscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x44 bytes\t\r\n \t[Native to Managed Transition]\t\r\n```"},"comment":{"url":"https://api.github.com/repos/NLog/NLog/issues/comments/166898667","html_url":"https://github.com/NLog/NLog/issues/1058#issuecomment-166898667","issue_url":"https://api.github.com/repos/NLog/NLog/issues/1058","id":166898667,"user":{"login":"kt1996","id":15853215,"avatar_url":"https://avatars.githubusercontent.com/u/15853215?v=3","gravatar_id":"","url":"https://api.github.com/users/kt1996","html_url":"https://github.com/kt1996","followers_url":"https://api.github.com/users/kt1996/followers","following_url":"https://api.github.com/users/kt1996/following{/other_user}","gists_url":"https://api.github.com/users/kt1996/gists{/gist_id}","starred_url":"https://api.github.com/users/kt1996/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kt1996/subscriptions","organizations_url":"https://api.github.com/users/kt1996/orgs","repos_url":"https://api.github.com/users/kt1996/repos","events_url":"https://api.github.com/users/kt1996/events{/privacy}","received_events_url":"https://api.github.com/users/kt1996/received_events","type":"User","site_admin":false},"created_at":"2015-12-23T13:42:50Z","updated_at":"2015-12-23T13:42:50Z","body":"Hey,\r\n     I am a new guy and am trying to contribute to open source development. I am familiar with threading, network programming but have built only standalone single project applications, so am having a little bit difficulty in getting this running. \r\nFor debugging I am unable to figure out where should I put the configuration as no exe file is generated in build folder, with which I could put the NLog.config file alongside.  I have got a test console project running and logging with no target as no config.\r\nI am an interested newbie, and if you guys are ok, then maybe I can work on it for a start :-D...!!"}}