{"action":"opened","number":42,"pull_request":{"url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/pulls/42","id":146428275,"html_url":"https://github.com/IBM-Swift/BlueSSLService/pull/42","diff_url":"https://github.com/IBM-Swift/BlueSSLService/pull/42.diff","patch_url":"https://github.com/IBM-Swift/BlueSSLService/pull/42.patch","issue_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/issues/42","number":42,"state":"open","locked":false,"title":"Correct error handling for SSL_ERROR_SSL","user":{"login":"djones6","id":17850918,"avatar_url":"https://avatars0.githubusercontent.com/u/17850918?v=4","gravatar_id":"","url":"https://api.github.com/users/djones6","html_url":"https://github.com/djones6","followers_url":"https://api.github.com/users/djones6/followers","following_url":"https://api.github.com/users/djones6/following{/other_user}","gists_url":"https://api.github.com/users/djones6/gists{/gist_id}","starred_url":"https://api.github.com/users/djones6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/djones6/subscriptions","organizations_url":"https://api.github.com/users/djones6/orgs","repos_url":"https://api.github.com/users/djones6/repos","events_url":"https://api.github.com/users/djones6/events{/privacy}","received_events_url":"https://api.github.com/users/djones6/received_events","type":"User","site_admin":false},"body":"<!--- Provide a general summary of your changes in the Title above -->\r\n\r\n## Description\r\n<!--- Describe your changes in detail -->\r\nThis PR fixes two things in the Linux (openssl) implementation:\r\n- Inserts missing calls to `ERR_clear_error` prior to functions that may require `SSL_get_error` to be called\r\n- Corrects the logic for obtaining the detailed error description for the `SSL_ERROR_SSL` case.\r\n\r\n## Motivation and Context\r\n<!--- Why is this change required? What problem does it solve? -->\r\n<!--- If it fixes an open issue, please link to the issue here. -->\r\nThis resolves an intermittent failure exposed by a test added to Kitura-net (https://github.com/IBM-Swift/Kitura-net/pull/219), where the test can cause an SSL protocol error (`SSL_ERROR_SSL`).\r\n\r\nWhen this occurs, an error is placed onto that thread's error queue, however the `throwLastError` function did not call `ERR_get_error` in this case, instead reporting \"Could not determine error reason.\" and leaving the error on the queue.\r\n\r\nThe next SSL call with a non-zero return on that thread would then trigger a call to `SSL_get_error`, which would incorrectly pick up the error on the queue, incorrectly reporting another `SSL_ERROR_SSL`.\r\n\r\nPart of the contract of `SSL_get_error` is that the error queue must have been cleared before a call to `SSL_read`, `SSL_accept`, etc. is made.  To ensure we obey this contract, I have added `ERR_clear_error` before each such call.\r\n\r\n## How Has This Been Tested?\r\n<!--- Please describe in detail how you tested your changes. -->\r\n<!--- Include details of your testing environment, and the tests you ran to -->\r\n<!--- see how your change affects other areas of the code, etc. -->\r\nI have run the Kitura-net tests and they pass.\r\n\r\nSince we do not have a test that deliberately or reliably causes an SSL protocol error,  to test the output of the error reporting,  I modified a test locally to remove the SSL delegate from the client-side socket and then send some erroneous data.  This results in the following output:\r\n```\r\n[ERROR] [IncomingSocketHandler.swift:153 handleRead()] Read from socket (file descriptor 15) failed. Error = Error code: 336130315(0x1408F10B), ERROR: SSL_read, code: 336130315, reason: SSL3_GET_RECORD:wrong version number.\r\n```\r\n\r\n## Checklist:\r\n<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->\r\n<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->\r\n- [ ] I have submitted a [CLA form](https://github.com/IBM-Swift/CLA)\r\n- [ ] If applicable, I have updated the documentation accordingly.\r\n- [ ] If applicable, I have added tests to cover my changes.\r\n","created_at":"2017-10-13T10:55:01Z","updated_at":"2017-10-13T10:55:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/pulls/42/commits","review_comments_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/pulls/42/comments","review_comment_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/pulls/comments{/number}","comments_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/issues/42/comments","statuses_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/statuses/5955622276996c3c7e5fc68404a42cdb04655434","head":{"label":"djones6:debug","ref":"debug","sha":"5955622276996c3c7e5fc68404a42cdb04655434","user":{"login":"djones6","id":17850918,"avatar_url":"https://avatars0.githubusercontent.com/u/17850918?v=4","gravatar_id":"","url":"https://api.github.com/users/djones6","html_url":"https://github.com/djones6","followers_url":"https://api.github.com/users/djones6/followers","following_url":"https://api.github.com/users/djones6/following{/other_user}","gists_url":"https://api.github.com/users/djones6/gists{/gist_id}","starred_url":"https://api.github.com/users/djones6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/djones6/subscriptions","organizations_url":"https://api.github.com/users/djones6/orgs","repos_url":"https://api.github.com/users/djones6/repos","events_url":"https://api.github.com/users/djones6/events{/privacy}","received_events_url":"https://api.github.com/users/djones6/received_events","type":"User","site_admin":false},"repo":{"id":80195235,"name":"BlueSSLService","full_name":"djones6/BlueSSLService","owner":{"login":"djones6","id":17850918,"avatar_url":"https://avatars0.githubusercontent.com/u/17850918?v=4","gravatar_id":"","url":"https://api.github.com/users/djones6","html_url":"https://github.com/djones6","followers_url":"https://api.github.com/users/djones6/followers","following_url":"https://api.github.com/users/djones6/following{/other_user}","gists_url":"https://api.github.com/users/djones6/gists{/gist_id}","starred_url":"https://api.github.com/users/djones6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/djones6/subscriptions","organizations_url":"https://api.github.com/users/djones6/orgs","repos_url":"https://api.github.com/users/djones6/repos","events_url":"https://api.github.com/users/djones6/events{/privacy}","received_events_url":"https://api.github.com/users/djones6/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/djones6/BlueSSLService","description":"SSL/TLS Add-in for BlueSocket using Secure Transport and OpenSSL","fork":true,"url":"https://api.github.com/repos/djones6/BlueSSLService","forks_url":"https://api.github.com/repos/djones6/BlueSSLService/forks","keys_url":"https://api.github.com/repos/djones6/BlueSSLService/keys{/key_id}","collaborators_url":"https://api.github.com/repos/djones6/BlueSSLService/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/djones6/BlueSSLService/teams","hooks_url":"https://api.github.com/repos/djones6/BlueSSLService/hooks","issue_events_url":"https://api.github.com/repos/djones6/BlueSSLService/issues/events{/number}","events_url":"https://api.github.com/repos/djones6/BlueSSLService/events","assignees_url":"https://api.github.com/repos/djones6/BlueSSLService/assignees{/user}","branches_url":"https://api.github.com/repos/djones6/BlueSSLService/branches{/branch}","tags_url":"https://api.github.com/repos/djones6/BlueSSLService/tags","blobs_url":"https://api.github.com/repos/djones6/BlueSSLService/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/djones6/BlueSSLService/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/djones6/BlueSSLService/git/refs{/sha}","trees_url":"https://api.github.com/repos/djones6/BlueSSLService/git/trees{/sha}","statuses_url":"https://api.github.com/repos/djones6/BlueSSLService/statuses/{sha}","languages_url":"https://api.github.com/repos/djones6/BlueSSLService/languages","stargazers_url":"https://api.github.com/repos/djones6/BlueSSLService/stargazers","contributors_url":"https://api.github.com/repos/djones6/BlueSSLService/contributors","subscribers_url":"https://api.github.com/repos/djones6/BlueSSLService/subscribers","subscription_url":"https://api.github.com/repos/djones6/BlueSSLService/subscription","commits_url":"https://api.github.com/repos/djones6/BlueSSLService/commits{/sha}","git_commits_url":"https://api.github.com/repos/djones6/BlueSSLService/git/commits{/sha}","comments_url":"https://api.github.com/repos/djones6/BlueSSLService/comments{/number}","issue_comment_url":"https://api.github.com/repos/djones6/BlueSSLService/issues/comments{/number}","contents_url":"https://api.github.com/repos/djones6/BlueSSLService/contents/{+path}","compare_url":"https://api.github.com/repos/djones6/BlueSSLService/compare/{base}...{head}","merges_url":"https://api.github.com/repos/djones6/BlueSSLService/merges","archive_url":"https://api.github.com/repos/djones6/BlueSSLService/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/djones6/BlueSSLService/downloads","issues_url":"https://api.github.com/repos/djones6/BlueSSLService/issues{/number}","pulls_url":"https://api.github.com/repos/djones6/BlueSSLService/pulls{/number}","milestones_url":"https://api.github.com/repos/djones6/BlueSSLService/milestones{/number}","notifications_url":"https://api.github.com/repos/djones6/BlueSSLService/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/djones6/BlueSSLService/labels{/name}","releases_url":"https://api.github.com/repos/djones6/BlueSSLService/releases{/id}","deployments_url":"https://api.github.com/repos/djones6/BlueSSLService/deployments","created_at":"2017-01-27T09:32:06Z","updated_at":"2017-01-27T09:32:08Z","pushed_at":"2017-10-13T10:37:06Z","git_url":"git://github.com/djones6/BlueSSLService.git","ssh_url":"git@github.com:djones6/BlueSSLService.git","clone_url":"https://github.com/djones6/BlueSSLService.git","svn_url":"https://github.com/djones6/BlueSSLService","homepage":"","size":205,"stargazers_count":0,"watchers_count":0,"language":"Swift","has_issues":false,"has_projects":true,"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":"IBM-Swift:master","ref":"master","sha":"1e69d878a34e5889b506baa8f349b6444edb0449","user":{"login":"IBM-Swift","id":16882981,"avatar_url":"https://avatars3.githubusercontent.com/u/16882981?v=4","gravatar_id":"","url":"https://api.github.com/users/IBM-Swift","html_url":"https://github.com/IBM-Swift","followers_url":"https://api.github.com/users/IBM-Swift/followers","following_url":"https://api.github.com/users/IBM-Swift/following{/other_user}","gists_url":"https://api.github.com/users/IBM-Swift/gists{/gist_id}","starred_url":"https://api.github.com/users/IBM-Swift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IBM-Swift/subscriptions","organizations_url":"https://api.github.com/users/IBM-Swift/orgs","repos_url":"https://api.github.com/users/IBM-Swift/repos","events_url":"https://api.github.com/users/IBM-Swift/events{/privacy}","received_events_url":"https://api.github.com/users/IBM-Swift/received_events","type":"Organization","site_admin":false},"repo":{"id":59753581,"name":"BlueSSLService","full_name":"IBM-Swift/BlueSSLService","owner":{"login":"IBM-Swift","id":16882981,"avatar_url":"https://avatars3.githubusercontent.com/u/16882981?v=4","gravatar_id":"","url":"https://api.github.com/users/IBM-Swift","html_url":"https://github.com/IBM-Swift","followers_url":"https://api.github.com/users/IBM-Swift/followers","following_url":"https://api.github.com/users/IBM-Swift/following{/other_user}","gists_url":"https://api.github.com/users/IBM-Swift/gists{/gist_id}","starred_url":"https://api.github.com/users/IBM-Swift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IBM-Swift/subscriptions","organizations_url":"https://api.github.com/users/IBM-Swift/orgs","repos_url":"https://api.github.com/users/IBM-Swift/repos","events_url":"https://api.github.com/users/IBM-Swift/events{/privacy}","received_events_url":"https://api.github.com/users/IBM-Swift/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/IBM-Swift/BlueSSLService","description":"SSL/TLS Add-in for BlueSocket using Secure Transport and OpenSSL","fork":false,"url":"https://api.github.com/repos/IBM-Swift/BlueSSLService","forks_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/forks","keys_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/keys{/key_id}","collaborators_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/teams","hooks_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/hooks","issue_events_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/issues/events{/number}","events_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/events","assignees_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/assignees{/user}","branches_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/branches{/branch}","tags_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/tags","blobs_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/git/refs{/sha}","trees_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/git/trees{/sha}","statuses_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/statuses/{sha}","languages_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/languages","stargazers_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/stargazers","contributors_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/contributors","subscribers_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/subscribers","subscription_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/subscription","commits_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/commits{/sha}","git_commits_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/git/commits{/sha}","comments_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/comments{/number}","issue_comment_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/issues/comments{/number}","contents_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/contents/{+path}","compare_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/compare/{base}...{head}","merges_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/merges","archive_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/downloads","issues_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/issues{/number}","pulls_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/pulls{/number}","milestones_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/milestones{/number}","notifications_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/labels{/name}","releases_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/releases{/id}","deployments_url":"https://api.github.com/repos/IBM-Swift/BlueSSLService/deployments","created_at":"2016-05-26T13:43:43Z","updated_at":"2017-10-08T05:39:36Z","pushed_at":"2017-10-12T14:32:36Z","git_url":"git://github.com/IBM-Swift/BlueSSLService.git","ssh_url":"git@github.com:IBM-Swift/BlueSSLService.git","clone_url":"https://github.com/IBM-Swift/BlueSSLService.git","svn_url":"https://github.com/IBM-Swift/BlueSSLService","homepage":"","size":193,"stargazers_count":41,"watchers_count":41,"language":"Swift","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":23,"mirror_url":null,"open_issues_count":6,"forks":23,"open_issues":6,"watchers":41,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/IBM-Swift/BlueSSLService/pulls/42"},"html":{"href":"https://github.com/IBM-Swift/BlueSSLService/pull/42"},"issue":{"href":"https://api.github.com/repos/IBM-Swift/BlueSSLService/issues/42"},"comments":{"href":"https://api.github.com/repos/IBM-Swift/BlueSSLService/issues/42/comments"},"review_comments":{"href":"https://api.github.com/repos/IBM-Swift/BlueSSLService/pulls/42/comments"},"review_comment":{"href":"https://api.github.com/repos/IBM-Swift/BlueSSLService/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/IBM-Swift/BlueSSLService/pulls/42/commits"},"statuses":{"href":"https://api.github.com/repos/IBM-Swift/BlueSSLService/statuses/5955622276996c3c7e5fc68404a42cdb04655434"}},"author_association":"MEMBER","merged":false,"mergeable":null,"rebaseable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"maintainer_can_modify":true,"commits":2,"additions":9,"deletions":1,"changed_files":1}}
{"actor":{"display_login":"djones6"}}