{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/22658","repository_url":"https://api.github.com/repos/dotnet/roslyn","labels_url":"https://api.github.com/repos/dotnet/roslyn/issues/22658/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/22658/comments","events_url":"https://api.github.com/repos/dotnet/roslyn/issues/22658/events","html_url":"https://github.com/dotnet/roslyn/pull/22658","id":264563331,"number":22658,"title":"Prevent SqlConnection from being held past an async boundary","user":{"login":"sharwell","id":1408396,"avatar_url":"https://avatars1.githubusercontent.com/u/1408396?v=4","gravatar_id":"","url":"https://api.github.com/users/sharwell","html_url":"https://github.com/sharwell","followers_url":"https://api.github.com/users/sharwell/followers","following_url":"https://api.github.com/users/sharwell/following{/other_user}","gists_url":"https://api.github.com/users/sharwell/gists{/gist_id}","starred_url":"https://api.github.com/users/sharwell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sharwell/subscriptions","organizations_url":"https://api.github.com/users/sharwell/orgs","repos_url":"https://api.github.com/users/sharwell/repos","events_url":"https://api.github.com/users/sharwell/events{/privacy}","received_events_url":"https://api.github.com/users/sharwell/received_events","type":"User","site_admin":false},"labels":[{"id":197452922,"url":"https://api.github.com/repos/dotnet/roslyn/labels/cla-already-signed","name":"cla-already-signed","color":"FFFFFF","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":44,"created_at":"2017-10-11T12:15:13Z","updated_at":"2017-10-12T11:05:56Z","closed_at":null,"author_association":"MEMBER","pull_request":{"url":"https://api.github.com/repos/dotnet/roslyn/pulls/22658","html_url":"https://github.com/dotnet/roslyn/pull/22658","diff_url":"https://github.com/dotnet/roslyn/pull/22658.diff","patch_url":"https://github.com/dotnet/roslyn/pull/22658.patch"},"body":"Fixes #22650\r\n\r\nRather than place a hard cap on the number of connections, I updated the code to ensure database connections are only held for the duration where they are actually in use.\r\n\r\nCC: @dotnet/roslyn-ide @heejaechang @CyrusNajmabadi @onyxmaster\r\n\r\n**Customer scenario**\r\n\r\nA customer opens a large solution with 15.3 or 15.4. The IDE is at high risk for encountering OOM errors.\r\n\r\n**Bugs this fixes:**\r\n\r\n#22650 \r\n[DevDiv 507560](https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems/edit/507560)\r\n\r\n**Workarounds, if any**\r\n\r\nNone\r\n\r\n**Risk**\r\n\r\nRelatively low.\r\n\r\n**Performance impact**\r\n\r\nFor scenarios where database writes to disk are slow, performance is improved by allowing database connection sharing.\r\n\r\n**Is this a regression from a previous update?**\r\n\r\nYes.\r\n\r\n**Root cause analysis:**\r\n\r\nAs a best guess:\r\n\r\n1. Our drives are faster, so we didn't observe the stalls locally (a local reproducer would mean we could sample the native allocations at runtime to get call stacks, as opposed to looking at a heap dump post-mortem)\r\n2. The memory allocation impacting the process was a native memory allocation, which we were aware in statistics but did not have insight into the cause (we now know to treat the managed `SqlConnection` and `sqlite3` objects as heavier to account for this, similar to what we already did for `MemoryMappedView`)\r\n\r\n**How was the bug found?**\r\n\r\nThe 425600 byte allocation pattern was discovered by Lee Culver on the .NET Fundamentals team. Text contents in some of these blocks made me suspicious of SQLite, leading me to search for \"425600 SQLite\". The value appeared twice in interesting results:\r\n\r\nhttps://forums.plex.tv/discussion/256008/pms-crashes-randomly-under-load\r\n\r\n> ERROR - SQLITE3:1B3E069A, 7, failed to allocate 425600 bytes of memory\r\n\r\nhttp://iamoracleadmin.blogspot.com/p/sqlite-cheat-sheet.html\r\n\r\n> Largest Allocation: 425600 bytes\r\n\r\nI then used PerfView to review the number of connections present in the managed heap, and found it exactly matched the number of native allocations.\r\n\r\n**Test documentation updated?**\r\n\r\nN/A"},"comment":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/comments/336095690","html_url":"https://github.com/dotnet/roslyn/pull/22658#issuecomment-336095690","issue_url":"https://api.github.com/repos/dotnet/roslyn/issues/22658","id":336095690,"user":{"login":"sharwell","id":1408396,"avatar_url":"https://avatars1.githubusercontent.com/u/1408396?v=4","gravatar_id":"","url":"https://api.github.com/users/sharwell","html_url":"https://github.com/sharwell","followers_url":"https://api.github.com/users/sharwell/followers","following_url":"https://api.github.com/users/sharwell/following{/other_user}","gists_url":"https://api.github.com/users/sharwell/gists{/gist_id}","starred_url":"https://api.github.com/users/sharwell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sharwell/subscriptions","organizations_url":"https://api.github.com/users/sharwell/orgs","repos_url":"https://api.github.com/users/sharwell/repos","events_url":"https://api.github.com/users/sharwell/events{/privacy}","received_events_url":"https://api.github.com/users/sharwell/received_events","type":"User","site_admin":false},"created_at":"2017-10-12T11:05:56Z","updated_at":"2017-10-12T11:05:56Z","author_association":"MEMBER","body":"@onyxmaster Sounds like I need to bring #21800 back as well, and then update it to treat BUSY and LOCKED the same way."}}
{"actor":{"display_login":"sharwell"}}