{"action":"created","comment":{"url":"https://api.github.com/repos/dotnet/orleans/pulls/comments/68893048","id":68893048,"diff_hunk":"@@ -434,11 +435,34 @@ private void SafeSendResponse(Message message, object resultObject)\n             }\n         }\n \n+        private static readonly Lazy<Func<Exception, Exception>> prepForRemotingLazy = \n+            new Lazy<Func<Exception, Exception>>(() =>\n+            {\n+                ParameterExpression exceptionParameter = Expression.Parameter(typeof(Exception));\n+                MethodCallExpression prepForRemotingCall = Expression.Call(exceptionParameter, \"PrepForRemoting\", Type.EmptyTypes);\n+                Expression<Func<Exception, Exception>> lambda = Expression.Lambda<Func<Exception, Exception>>(prepForRemotingCall, exceptionParameter);\n+                Func<Exception, Exception> func = lambda.Compile();\n+                return func;\n+            });\n+\n+        private static Exception PrepareForRemoting(Exception exception)\n+        {\n+            // Call the Exception.PrepForRemoting internal method, which preserves the original stack when the exception\n+            // is rethrown at the remote site (and appends the call site stacktrace). If this is not done, then when the\n+            // exception is rethrown the original stacktrace is entire replaced.\n+            // Note: another commonly used approach since .NET 4.5 is to use ExceptionDispatchInfo.Capture(ex).Throw()\n+            // but that involves rethrowing the exception in-place, which is not what we want here, but could in theory","path":"src/OrleansRuntime/Core/InsideRuntimeClient.cs","position":28,"original_position":28,"commit_id":"7578954e8971d090c0caa9d6afacda59ed0bcc36","original_commit_id":"7578954e8971d090c0caa9d6afacda59ed0bcc36","user":{"login":"jdom","id":1361686,"avatar_url":"https://avatars.githubusercontent.com/u/1361686?v=3","gravatar_id":"","url":"https://api.github.com/users/jdom","html_url":"https://github.com/jdom","followers_url":"https://api.github.com/users/jdom/followers","following_url":"https://api.github.com/users/jdom/following{/other_user}","gists_url":"https://api.github.com/users/jdom/gists{/gist_id}","starred_url":"https://api.github.com/users/jdom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdom/subscriptions","organizations_url":"https://api.github.com/users/jdom/orgs","repos_url":"https://api.github.com/users/jdom/repos","events_url":"https://api.github.com/users/jdom/events{/privacy}","received_events_url":"https://api.github.com/users/jdom/received_events","type":"User","site_admin":false},"body":"Because this is the remote site before we send it through the wire. We need to rethrow the exception at the other end of the wire. Doable, but requires some extra non trivial work (due to the threading subtleties that you already know)  that I prefer to take on once we move to NET 4.6 (otherwise the fix will have to be postponed, and it's pretty important for troubleshooting) ","created_at":"2016-06-29T06:42:06Z","updated_at":"2016-06-29T06:42:06Z","html_url":"https://github.com/dotnet/orleans/pull/1879#discussion_r68893048","pull_request_url":"https://api.github.com/repos/dotnet/orleans/pulls/1879","_links":{"self":{"href":"https://api.github.com/repos/dotnet/orleans/pulls/comments/68893048"},"html":{"href":"https://github.com/dotnet/orleans/pull/1879#discussion_r68893048"},"pull_request":{"href":"https://api.github.com/repos/dotnet/orleans/pulls/1879"}}},"pull_request":{"url":"https://api.github.com/repos/dotnet/orleans/pulls/1879","id":75399187,"html_url":"https://github.com/dotnet/orleans/pull/1879","diff_url":"https://github.com/dotnet/orleans/pull/1879.diff","patch_url":"https://github.com/dotnet/orleans/pull/1879.patch","issue_url":"https://api.github.com/repos/dotnet/orleans/issues/1879","number":1879,"state":"closed","locked":false,"title":"Stacktrace preservation when sending exception to a remote process.","user":{"login":"jdom","id":1361686,"avatar_url":"https://avatars.githubusercontent.com/u/1361686?v=3","gravatar_id":"","url":"https://api.github.com/users/jdom","html_url":"https://github.com/jdom","followers_url":"https://api.github.com/users/jdom/followers","following_url":"https://api.github.com/users/jdom/following{/other_user}","gists_url":"https://api.github.com/users/jdom/gists{/gist_id}","starred_url":"https://api.github.com/users/jdom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdom/subscriptions","organizations_url":"https://api.github.com/users/jdom/orgs","repos_url":"https://api.github.com/users/jdom/repos","events_url":"https://api.github.com/users/jdom/events{/privacy}","received_events_url":"https://api.github.com/users/jdom/received_events","type":"User","site_admin":false},"body":"Previously the stacktrace was being sent along the exception remotely, but as soon as the client awaited the grain call, the exception was being re-thrown on the caller side and the original stacktrace was being wiped out.\r\nThis prepares the exception to be able to be re-thrown at a remote place without wiping out the stacktrace when that's done.","created_at":"2016-06-27T23:59:05Z","updated_at":"2016-06-29T06:42:06Z","closed_at":"2016-06-28T15:14:06Z","merged_at":"2016-06-28T15:14:06Z","merge_commit_sha":"d2f70dc1077aa658a6dbfe1798e577204251b600","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/dotnet/orleans/pulls/1879/commits","review_comments_url":"https://api.github.com/repos/dotnet/orleans/pulls/1879/comments","review_comment_url":"https://api.github.com/repos/dotnet/orleans/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dotnet/orleans/issues/1879/comments","statuses_url":"https://api.github.com/repos/dotnet/orleans/statuses/7578954e8971d090c0caa9d6afacda59ed0bcc36","head":{"label":"jdom:stacktrace-preservation","ref":"stacktrace-preservation","sha":"7578954e8971d090c0caa9d6afacda59ed0bcc36","user":{"login":"jdom","id":1361686,"avatar_url":"https://avatars.githubusercontent.com/u/1361686?v=3","gravatar_id":"","url":"https://api.github.com/users/jdom","html_url":"https://github.com/jdom","followers_url":"https://api.github.com/users/jdom/followers","following_url":"https://api.github.com/users/jdom/following{/other_user}","gists_url":"https://api.github.com/users/jdom/gists{/gist_id}","starred_url":"https://api.github.com/users/jdom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdom/subscriptions","organizations_url":"https://api.github.com/users/jdom/orgs","repos_url":"https://api.github.com/users/jdom/repos","events_url":"https://api.github.com/users/jdom/events{/privacy}","received_events_url":"https://api.github.com/users/jdom/received_events","type":"User","site_admin":false},"repo":{"id":38893383,"name":"orleans","full_name":"jdom/orleans","owner":{"login":"jdom","id":1361686,"avatar_url":"https://avatars.githubusercontent.com/u/1361686?v=3","gravatar_id":"","url":"https://api.github.com/users/jdom","html_url":"https://github.com/jdom","followers_url":"https://api.github.com/users/jdom/followers","following_url":"https://api.github.com/users/jdom/following{/other_user}","gists_url":"https://api.github.com/users/jdom/gists{/gist_id}","starred_url":"https://api.github.com/users/jdom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdom/subscriptions","organizations_url":"https://api.github.com/users/jdom/orgs","repos_url":"https://api.github.com/users/jdom/repos","events_url":"https://api.github.com/users/jdom/events{/privacy}","received_events_url":"https://api.github.com/users/jdom/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jdom/orleans","description":"Orleans - Distributed Virtual Actor Model","fork":true,"url":"https://api.github.com/repos/jdom/orleans","forks_url":"https://api.github.com/repos/jdom/orleans/forks","keys_url":"https://api.github.com/repos/jdom/orleans/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jdom/orleans/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jdom/orleans/teams","hooks_url":"https://api.github.com/repos/jdom/orleans/hooks","issue_events_url":"https://api.github.com/repos/jdom/orleans/issues/events{/number}","events_url":"https://api.github.com/repos/jdom/orleans/events","assignees_url":"https://api.github.com/repos/jdom/orleans/assignees{/user}","branches_url":"https://api.github.com/repos/jdom/orleans/branches{/branch}","tags_url":"https://api.github.com/repos/jdom/orleans/tags","blobs_url":"https://api.github.com/repos/jdom/orleans/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jdom/orleans/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jdom/orleans/git/refs{/sha}","trees_url":"https://api.github.com/repos/jdom/orleans/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jdom/orleans/statuses/{sha}","languages_url":"https://api.github.com/repos/jdom/orleans/languages","stargazers_url":"https://api.github.com/repos/jdom/orleans/stargazers","contributors_url":"https://api.github.com/repos/jdom/orleans/contributors","subscribers_url":"https://api.github.com/repos/jdom/orleans/subscribers","subscription_url":"https://api.github.com/repos/jdom/orleans/subscription","commits_url":"https://api.github.com/repos/jdom/orleans/commits{/sha}","git_commits_url":"https://api.github.com/repos/jdom/orleans/git/commits{/sha}","comments_url":"https://api.github.com/repos/jdom/orleans/comments{/number}","issue_comment_url":"https://api.github.com/repos/jdom/orleans/issues/comments{/number}","contents_url":"https://api.github.com/repos/jdom/orleans/contents/{+path}","compare_url":"https://api.github.com/repos/jdom/orleans/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jdom/orleans/merges","archive_url":"https://api.github.com/repos/jdom/orleans/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jdom/orleans/downloads","issues_url":"https://api.github.com/repos/jdom/orleans/issues{/number}","pulls_url":"https://api.github.com/repos/jdom/orleans/pulls{/number}","milestones_url":"https://api.github.com/repos/jdom/orleans/milestones{/number}","notifications_url":"https://api.github.com/repos/jdom/orleans/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jdom/orleans/labels{/name}","releases_url":"https://api.github.com/repos/jdom/orleans/releases{/id}","deployments_url":"https://api.github.com/repos/jdom/orleans/deployments","created_at":"2015-07-10T17:33:29Z","updated_at":"2016-03-16T16:08:01Z","pushed_at":"2016-06-28T00:30:06Z","git_url":"git://github.com/jdom/orleans.git","ssh_url":"git@github.com:jdom/orleans.git","clone_url":"https://github.com/jdom/orleans.git","svn_url":"https://github.com/jdom/orleans","homepage":"http://dotnet.github.io/orleans","size":14634,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"dotnet:master","ref":"master","sha":"36cd830eb3435d8def92f25b0b7b657c860dfe28","user":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars.githubusercontent.com/u/9141961?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"repo":{"id":28232663,"name":"orleans","full_name":"dotnet/orleans","owner":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars.githubusercontent.com/u/9141961?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dotnet/orleans","description":"Orleans - Distributed Virtual Actor Model","fork":false,"url":"https://api.github.com/repos/dotnet/orleans","forks_url":"https://api.github.com/repos/dotnet/orleans/forks","keys_url":"https://api.github.com/repos/dotnet/orleans/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dotnet/orleans/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dotnet/orleans/teams","hooks_url":"https://api.github.com/repos/dotnet/orleans/hooks","issue_events_url":"https://api.github.com/repos/dotnet/orleans/issues/events{/number}","events_url":"https://api.github.com/repos/dotnet/orleans/events","assignees_url":"https://api.github.com/repos/dotnet/orleans/assignees{/user}","branches_url":"https://api.github.com/repos/dotnet/orleans/branches{/branch}","tags_url":"https://api.github.com/repos/dotnet/orleans/tags","blobs_url":"https://api.github.com/repos/dotnet/orleans/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dotnet/orleans/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dotnet/orleans/git/refs{/sha}","trees_url":"https://api.github.com/repos/dotnet/orleans/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dotnet/orleans/statuses/{sha}","languages_url":"https://api.github.com/repos/dotnet/orleans/languages","stargazers_url":"https://api.github.com/repos/dotnet/orleans/stargazers","contributors_url":"https://api.github.com/repos/dotnet/orleans/contributors","subscribers_url":"https://api.github.com/repos/dotnet/orleans/subscribers","subscription_url":"https://api.github.com/repos/dotnet/orleans/subscription","commits_url":"https://api.github.com/repos/dotnet/orleans/commits{/sha}","git_commits_url":"https://api.github.com/repos/dotnet/orleans/git/commits{/sha}","comments_url":"https://api.github.com/repos/dotnet/orleans/comments{/number}","issue_comment_url":"https://api.github.com/repos/dotnet/orleans/issues/comments{/number}","contents_url":"https://api.github.com/repos/dotnet/orleans/contents/{+path}","compare_url":"https://api.github.com/repos/dotnet/orleans/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dotnet/orleans/merges","archive_url":"https://api.github.com/repos/dotnet/orleans/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dotnet/orleans/downloads","issues_url":"https://api.github.com/repos/dotnet/orleans/issues{/number}","pulls_url":"https://api.github.com/repos/dotnet/orleans/pulls{/number}","milestones_url":"https://api.github.com/repos/dotnet/orleans/milestones{/number}","notifications_url":"https://api.github.com/repos/dotnet/orleans/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dotnet/orleans/labels{/name}","releases_url":"https://api.github.com/repos/dotnet/orleans/releases{/id}","deployments_url":"https://api.github.com/repos/dotnet/orleans/deployments","created_at":"2014-12-19T14:32:50Z","updated_at":"2016-06-29T04:28:29Z","pushed_at":"2016-06-28T18:46:44Z","git_url":"git://github.com/dotnet/orleans.git","ssh_url":"git@github.com:dotnet/orleans.git","clone_url":"https://github.com/dotnet/orleans.git","svn_url":"https://github.com/dotnet/orleans","homepage":"http://dotnet.github.io/orleans","size":44230,"stargazers_count":1919,"watchers_count":1919,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":484,"mirror_url":null,"open_issues_count":196,"forks":484,"open_issues":196,"watchers":1919,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dotnet/orleans/pulls/1879"},"html":{"href":"https://github.com/dotnet/orleans/pull/1879"},"issue":{"href":"https://api.github.com/repos/dotnet/orleans/issues/1879"},"comments":{"href":"https://api.github.com/repos/dotnet/orleans/issues/1879/comments"},"review_comments":{"href":"https://api.github.com/repos/dotnet/orleans/pulls/1879/comments"},"review_comment":{"href":"https://api.github.com/repos/dotnet/orleans/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dotnet/orleans/pulls/1879/commits"},"statuses":{"href":"https://api.github.com/repos/dotnet/orleans/statuses/7578954e8971d090c0caa9d6afacda59ed0bcc36"}}}}
{"actor":{"display_login":"jdom"}}