Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/known hosts fingerprint duplication error/upstream 1.0 #110

Merged
merged 4 commits into from
Jul 26, 2016
Merged

Fix/known hosts fingerprint duplication error/upstream 1.0 #110

merged 4 commits into from
Jul 26, 2016

Conversation

legraphista
Copy link
Contributor

@legraphista legraphista commented Jul 22, 2016

Fixes issue #107 & #108
Fix: loadFingerprint callback only called once
Fix: storeFingerprint does not duplicate information in the known_hosts file
Add: test cases

Stefan-Gabriel Muscalu added 2 commits July 22, 2016 15:01
…on the first one and not call the callback on `loadFingerprint` more than once
@zhenlineo
Copy link
Contributor

The two newly added tests failed on our test server.
The error messages are:

Failures: 
1) trust-on-first-use should not throw an error if the host file contains two host duplicates
1.1) Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
     Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
         at null._onTimeout (/opt/teamcity-agent/work/724ebdf14baddd87/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1909:23)
         at Timer.listOnTimeout (timers.js:92:15)

2) trust-on-first-use should not duplicate fingerprint entries
2.1) Expected 2 to be 1.
     Error: Expected 2 to be 1.
         at stack (/opt/teamcity-agent/work/724ebdf14baddd87/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1577:17)
         at buildExpectationResult (/opt/teamcity-agent/work/724ebdf14baddd87/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1547:14)
         at Spec.Env.expectationResultFactory (/opt/teamcity-agent/work/724ebdf14baddd87/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:638:18)
         at Spec.addExpectationResult (/opt/teamcity-agent/work/724ebdf14baddd87/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:330:34)
         at Expectation.addExpectationResult (/opt/teamcity-agent/work/724ebdf14baddd87/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:588:21)
         at Expectation.toBe (/opt/teamcity-agent/work/724ebdf14baddd87/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1501:12)
         at null._onTimeout (/opt/teamcity-agent/work/724ebdf14baddd87/test/internal/tls.test.js:167:76)
         at Timer.listOnTimeout (timers.js:92:15)

129 specs, 2 failures

I fixed the first error in #111, which is just because the server failed to connect to 7687 within timeout as the cert you created in the test is not real.

However the second one I have not think of a way to fix. The file DID have two fingerprints sometimes. I am guessing it might because the lock var cannot ensure the two processes seeing the change to the lock var immediately (a.k.a. the lock var is not atomic). So in #111 I ignored your second change. You are most welcome to submit your new changes if you know why this could happen.

To run the tests locally, the lazy way is run ./runTests.sh (or .\runTests.ps1 powershell script with admin right for windows). It will download and start/stop a server for you automatically. But make sure you have no real server running on 7474 in case the test clean your important db data in tests.

Thanks again for helping us!
Zhen

@legraphista
Copy link
Contributor Author

legraphista commented Jul 25, 2016

Its weird, I did run the tests locally and none failed. I tend to believe that somehow the tls.test.js did not run for me. I think it's because I ran npm run test without npm i first.

As for the lock var, NodeJS is single-threaded so there is no concept of mutex or atomicity, but running multiple node instances of the same code will not share the lock var and thus it cannot ensure uniqueness.

@legraphista
Copy link
Contributor Author

@zhenlineo The issue were the tests, I have fixed them in the last commit

@zhenlineo
Copy link
Contributor

I actually changed that line to expect( fs.readFileSync(knownHostsPath, 'utf8').split('\n').filter(v=>v!='').length ).toBe( 1 ); this morning but it still shows two to me sometime. The error happens around 1 out of 4 runs. Let me try this new one out tomorrow. Thanks a lot again.

@zhenlineo
Copy link
Contributor

  • Currently test server failed with an unrelated tck error. Working on a fix for the test server now so that this pr could get in without any error.

@legraphista
Copy link
Contributor Author

I will look into this, see if i can dig up a deeper issue

…ook for duplicate lines not just the number of them
@legraphista
Copy link
Contributor Author

I have reworked the test to check for duplicate lines, but I cannot reproduce the occasional 1 in 4 line duplicates that you are experiencing for should not duplicate fingerprint entries test.

@zhenlineo
Copy link
Contributor

It is still wrong in my local runs, but I will merge this PR and let the whole build system to go over the tests. Will let you know if the test is also flaky on test server. Otherwise, it might just my local settings is somehow wrong.

@zhenlineo zhenlineo merged commit 6006a2f into neo4j:1.0 Jul 26, 2016
@legraphista
Copy link
Contributor Author

Can you please detail a bit your setup, maybe I can reproduce it in a VM. Like OS and node version. I ran on OSX 10.11 with node 4.4.5 and 6.3.

@zhenlineo
Copy link
Contributor

I have OSX 10.11 with node 4.4.5. I got the error if I run with fdescribe on trust-on-first-use tests only. The whole build server accept the change without any error. So maybe just some thing wrong with my own machine.

@legraphista
Copy link
Contributor Author

legraphista commented Jul 26, 2016

@zhenlineo Using fdescribe yielded the issue that you were describing. I have fixed and pushed it to the same branch. I will open another pull request and try do describe the issue.

zhenlineo pushed a commit that referenced this pull request Aug 4, 2016
…duplication-error/1.0

Fix: regarding PR #110 edge cases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants