{"action":"created","issue":{"url":"https://api.github.com/repos/NLog/NLog/issues/2933","repository_url":"https://api.github.com/repos/NLog/NLog","labels_url":"https://api.github.com/repos/NLog/NLog/issues/2933/labels{/name}","comments_url":"https://api.github.com/repos/NLog/NLog/issues/2933/comments","events_url":"https://api.github.com/repos/NLog/NLog/issues/2933/events","html_url":"https://github.com/NLog/NLog/issues/2933","id":363301901,"node_id":"MDU6SXNzdWUzNjMzMDE5MDE=","number":2933,"title":"Memory Leak with async target and usage of ${threadid}, GDC or MLDC in the layout.","user":{"login":"staufour","id":4014315,"node_id":"MDQ6VXNlcjQwMTQzMTU=","avatar_url":"https://avatars0.githubusercontent.com/u/4014315?v=4","gravatar_id":"","url":"https://api.github.com/users/staufour","html_url":"https://github.com/staufour","followers_url":"https://api.github.com/users/staufour/followers","following_url":"https://api.github.com/users/staufour/following{/other_user}","gists_url":"https://api.github.com/users/staufour/gists{/gist_id}","starred_url":"https://api.github.com/users/staufour/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/staufour/subscriptions","organizations_url":"https://api.github.com/users/staufour/orgs","repos_url":"https://api.github.com/users/staufour/repos","events_url":"https://api.github.com/users/staufour/events{/privacy}","received_events_url":"https://api.github.com/users/staufour/received_events","type":"User","site_admin":false},"labels":[{"id":295599144,"node_id":"MDU6TGFiZWwyOTU1OTkxNDQ=","url":"https://api.github.com/repos/NLog/NLog/labels/performance","name":"performance","color":"5319e7","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-09-24T20:11:30Z","updated_at":"2018-09-24T21:09:57Z","closed_at":null,"author_association":"NONE","body":"**NLog version**: 4.5.10\r\n\r\n**Platform**: .Net 4.5\r\n\r\n**Current NLog config**\r\n\r\n```xml\r\n<nlog xmlns=\"http://www.nlog-project.org/schemas/NLog.xsd\"\r\n      xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n\r\n  <targets async=\"true\">\r\n    <target name=\"logfile\" xsi:type=\"File\" fileName=\"log.txt\">\r\n      <layout xsi:type=\"CsvLayout\">\r\n        <withHeader>true</withHeader>\r\n        <column name=\"Date\" layout=\"${date:universalTime=True:format=o}\" />\r\n        <column name=\"Server\" layout=\"${machinename}\" />\r\n        <column name=\"Logger\" layout=\"${logger}\" />\r\n        <column name=\"Source\" layout=\"${callsite}\" />\r\n        <column name=\"Level\" layout=\"${level}\" />\r\n        <column name=\"Message\" layout=\"${message}\" />\r\n        <column name=\"Exception\" layout=\"${exception:format=ToString}\" />\r\n      </layout>\r\n    </target>\r\n    <target name=\"logfile_crash\" xsi:type=\"File\" fileName=\"log_crash.txt\">\r\n      <layout xsi:type=\"CsvLayout\">\r\n        <withHeader>true</withHeader>\r\n        <column name=\"Date\" layout=\"${date:universalTime=True:format=o}\" />\r\n        <column name=\"Server\" layout=\"${machinename}\" />\r\n        <!--<column name=\"ThreadId\" layout=\"${threadid}\" />-->\r\n        <column name=\"Application\" layout=\"${mdlc:item=Application}\" />\r\n        <!--<column name=\"Version\" layout=\"${gdc:item=Version}\" />-->\r\n        <column name=\"Logger\" layout=\"${logger}\" />\r\n        <column name=\"Source\" layout=\"${callsite}\" />\r\n        <column name=\"Level\" layout=\"${level}\" />\r\n        <column name=\"Message\" layout=\"${message}\" />\r\n        <column name=\"Exception\" layout=\"${exception:format=ToString}\" />\r\n      </layout>\r\n    </target>\r\n  </targets>\r\n\r\n  <rules>\r\n    <logger name=\"PerfTest\" minlevel=\"Info\" writeTo=\"logfile\" />\r\n    <logger name=\"PerfTestCrash\" minlevel=\"Info\" writeTo=\"logfile_crash\" />\r\n  </rules>\r\n</nlog>\r\n\r\n```\r\n\r\nHi,\r\n\r\nWe encounter a memory leak in our application in production, and the exploitation of memory dump led us to suspect NLog.\r\nAfter many tests, we realized that using an asynchronous target with a ${threadid}, GDC or MLDC in the layout causes the leak.\r\nThe current thread hang, the memory increases and the application finally crash.\r\n\r\nWe can reproduce quickly by logging large messages quickly.\r\n\r\nYou can find a test project here with the demonstration : https://github.com/staufour/LoggerPerfTest\r\n\r\nThanks for your help.\r\n"},"comment":{"url":"https://api.github.com/repos/NLog/NLog/issues/comments/424126067","html_url":"https://github.com/NLog/NLog/issues/2933#issuecomment-424126067","issue_url":"https://api.github.com/repos/NLog/NLog/issues/2933","id":424126067,"node_id":"MDEyOklzc3VlQ29tbWVudDQyNDEyNjA2Nw==","user":{"login":"snakefoot","id":11509660,"node_id":"MDQ6VXNlcjExNTA5NjYw","avatar_url":"https://avatars3.githubusercontent.com/u/11509660?v=4","gravatar_id":"","url":"https://api.github.com/users/snakefoot","html_url":"https://github.com/snakefoot","followers_url":"https://api.github.com/users/snakefoot/followers","following_url":"https://api.github.com/users/snakefoot/following{/other_user}","gists_url":"https://api.github.com/users/snakefoot/gists{/gist_id}","starred_url":"https://api.github.com/users/snakefoot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/snakefoot/subscriptions","organizations_url":"https://api.github.com/users/snakefoot/orgs","repos_url":"https://api.github.com/users/snakefoot/repos","events_url":"https://api.github.com/users/snakefoot/events{/privacy}","received_events_url":"https://api.github.com/users/snakefoot/received_events","type":"User","site_admin":false},"created_at":"2018-09-24T21:09:57Z","updated_at":"2018-09-24T21:09:57Z","author_association":"CONTRIBUTOR","body":"> @staufour And why the current hang with threadid or MDLC in the layout ? Without it is instantaneous with a thread in background\r\n\r\nYou are seeing the result of the NLog internal optimizations. When it doesn't have to capture the state of the current thread logging, then it can do both deferred async-formatting AND async-writing.\r\n\r\nBut when the target-layout specifies that thread-context-state has to be captured (Ex. current threadid). Then the thread doing the logging has to pay the price and will perform sync formatting. The async-writing is still deferred."}}
{"actor":{"display_login":"snakefoot"}}