Skip to content

Prevent registered names from leaking #322

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

Merged
merged 20 commits into from
Nov 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
629a6fa
Fix MX notification of re-registration events
hyperthunk Nov 12, 2018
2c9691b
Prevent registered names from leaking
hyperthunk Nov 12, 2018
467a611
Update comments to reflect what we're doing
hyperthunk Nov 12, 2018
d1d192a
roll back some nonsense in the tests
hyperthunk Nov 12, 2018
62329ce
Run both in-memory and using the tcp transport.
hyperthunk Nov 12, 2018
a064d81
Fix the potential for a clash/race over named management agents acros…
hyperthunk Nov 12, 2018
ab7368c
tidy up some more compilation warnings
hyperthunk Nov 12, 2018
9af7f8b
cosmetic
hyperthunk Nov 12, 2018
1984883
Whoops, forgot to update the travis config
hyperthunk Nov 12, 2018
df86d5a
avoid an inter-test dependency by ensuring all agents are dead and un…
hyperthunk Nov 12, 2018
7254c4b
Admit that test cases have to be synchronised
hyperthunk Nov 13, 2018
1d06898
try a bit harder to avoid races in the tests...
hyperthunk Nov 13, 2018
1cf2a29
Merge branch 'master' into reg-mx
hyperthunk Nov 13, 2018
02494f2
Hilariously, at no point in this patch had we started this service pr…
hyperthunk Nov 13, 2018
5b682ab
Refactor the tests to ensure they fail if we remove remote node updat…
hyperthunk Nov 13, 2018
0f99641
Remove test prog, since this patch set is not about console tracing
hyperthunk Nov 13, 2018
0dad31a
Now I'm at it with the random return ()
hyperthunk Nov 14, 2018
d3d343c
A more comprehensive build plan
hyperthunk Nov 15, 2018
a094396
Remove silly type error and fix compilation
hyperthunk Nov 15, 2018
a027f75
Remove the monitoring agent as it's not required
hyperthunk Nov 15, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ matrix:
include:
- env: ARGS="--stack-yaml stack-ghc-7.10.3.yaml"
addons: {apt: {packages: [libgmp-dev]}}

- env: ARGS="--stack-yaml stack-ghc-8.0.2.yaml"
- env: ARGS="--stack-yaml stack-ghc-8.2.2.yaml"
addons: {apt: {packages: [libgmp-dev]}}

- env: ARGS=
- env: ARGS="--stack-yaml stack-ghc-8.4.4.yaml"
addons: {apt: {packages: [libgmp-dev]}}
- env: ARGS="--stack-yaml stack-nightly.yaml --resolver nightly"
addons: {apt: {packages: [libgmp-dev]}}

cache:
Expand All @@ -34,5 +34,10 @@ script:
- stack ${ARGS} test $ARG='--plain -t "!Flaky"' ${TEST_PACKAGE}TestCHInTCP
- stack ${ARGS} test $ARG='--plain -t "!SpawnReconnect"' ${TEST_PACKAGE}TestClosure
- stack ${ARGS} test $ARG='--plain' ${TEST_PACKAGE}TestStats
- stack ${ARGS} test $ARG='--plain' ${TEST_PACKAGE}TestMx
- stack ${ARGS} test $ARG='--plain' ${TEST_PACKAGE}TestTracing
- stack ${ARGS} test $ARG='--plain' ${TEST_PACKAGE}TestMxInMemory
- stack ${ARGS} test $ARG='--plain' ${TEST_PACKAGE}TestMxInTCP
- stack ${ARGS} test $ARG='--plain' ${TEST_PACKAGE}TestTracingInMemory

notifications:
slack:
secure: LbqbNjK1KiHNiQo/i/Za4vkMD9l9mhmN+PWYFBQkNvGFWffSRayRKFrTqt4znV2p7h4dY1XZFoC7T5RemBVQLq2ppZAUWxkITeu1OUlnmVLDfJLeVYGTR/fn90nP6Y5ITE7T3A07nKmWaRbKpIgFBAOjzgqaM0csscDx3z0WW18=
19 changes: 16 additions & 3 deletions distributed-process-tests/distributed-process-tests.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ Test-Suite TestStats
ghc-options: -Wall -eventlog -threaded -rtsopts -with-rtsopts=-N -fno-warn-unused-do-bind
HS-Source-Dirs: tests


Test-Suite TestMx
Test-Suite TestMxInMemory
Type: exitcode-stdio-1.0
Main-Is: runInMemory.hs
CPP-Options: -DTEST_SUITE_MODULE=Control.Distributed.Process.Tests.Mx
Expand All @@ -129,7 +128,7 @@ Test-Suite TestMx
ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N -fno-warn-unused-do-bind
HS-Source-Dirs: tests

Test-Suite TestTracing
Test-Suite TestTracingInMemory
Type: exitcode-stdio-1.0
Main-Is: runInMemory.hs
CPP-Options: -DTEST_SUITE_MODULE=Control.Distributed.Process.Tests.Tracing
Expand All @@ -142,3 +141,17 @@ Test-Suite TestTracing
Extensions: CPP
ghc-options: -Wall -eventlog -threaded -rtsopts -with-rtsopts=-N -fno-warn-unused-do-bind
HS-Source-Dirs: tests

Test-Suite TestMxInTCP
Type: exitcode-stdio-1.0
Main-Is: runInMemory.hs
CPP-Options: -DTEST_SUITE_MODULE=Control.Distributed.Process.Tests.Mx
Build-Depends: base >= 4.4 && < 5,
distributed-process-tests,
network >= 2.3 && < 2.9,
network-transport >= 0.4.1.0 && < 0.6,
network-transport-inmemory >= 0.5,
test-framework >= 0.6 && < 0.9
Extensions: CPP
ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N -fno-warn-unused-do-bind
HS-Source-Dirs: tests
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ import Control.Distributed.Process.Internal.Types
, createUnencodedMessage
)
import Control.Distributed.Process.Node
import Control.Distributed.Process.Debug
import Control.Distributed.Process.Management.Internal.Types
import Control.Distributed.Process.Tests.Internal.Utils (shouldBe)
import Control.Distributed.Process.Serializable (Serializable)

import Test.HUnit (Assertion, assertBool, assertFailure)
Expand Down Expand Up @@ -1476,6 +1479,68 @@ testExitRemote TestTransport{..} = do
takeMVar supervisedDone
takeMVar supervisorDone

testRegistryMonitoring :: TestTransport -> Assertion
testRegistryMonitoring TestTransport{..} = do
node1 <- newLocalNode testTransport initRemoteTable
node2 <- newLocalNode testTransport initRemoteTable
waitH <- newEmptyMVar

let nid = localNodeId node2
pid <- forkProcess node1 $ do
getSelfPid >>= runUntilRegistered nid
liftIO $ takeMVar waitH

runProcess node2 $ do
register regName pid
res <- whereis regName
us <- getSelfPid
liftIO $ do
putMVar waitH ()
assertBool "expected (Just pid)" $ res == (Just pid)

-- This delay isn't essential!
-- The test case passes perfectly fine without it (feel free to comment out
-- and see), however waiting a few seconds here, makes it much more likely
-- that in delayUntilMaybeUnregistered we will hit the match case right
-- away, and thus not be subjected to a 20 second delay. The value of 4
-- seconds appears to work optimally on osx and across several linux distros
-- running in virtual machines (which is essentially what we do in CI)
void $ receiveTimeout 4000000 [ matchAny return ]

-- This delay doesn't serve much purpose in the happy path, however if some
-- future patch breaks the cooperative behaviour of node controllers viz
-- remote process registration and notification taking place via ncEffectDied,
-- there would be the possibility of a race in the test case should we attempt
-- to evaluate `whereis regName` on node2 right away. In case the name is still
-- erroneously registered, observing the 20 second delay (or lack of), could at
-- least give a hint that something is wrong, and we give up our time slice
-- so that there's a higher change the registrations have been cleaned up
-- in either case.
runProcess node2 $ delayUntilMaybeUnregistered nid pid

regHere <- newEmptyMVar
runProcess node2 $ whereis regName >>= liftIO . putMVar regHere
res <- takeMVar regHere
assertBool "expected Nothing, but process still registered" (res == Nothing)

where
runUntilRegistered nid us = do
whereisRemoteAsync nid regName
receiveWait [
matchIf (\(WhereIsReply n (Just p)) -> n == regName && p == us)
(const $ return ())
]

delayUntilMaybeUnregistered nid p = do
whereisRemoteAsync nid regName
receiveTimeout 20000000 {- 20 sec delay -} [
matchIf (\(WhereIsReply n p) -> n == regName && p == Nothing)
(const $ return ())
]
return ()

regName = "testRegisterRemote"

testUnsafeSend :: TestTransport -> Assertion
testUnsafeSend TestTransport{..} = do
serverAddr <- newEmptyMVar
Expand Down Expand Up @@ -1677,6 +1742,7 @@ tests testtrans = return [
, testCase "MaskRestoreScope" (testMaskRestoreScope testtrans)
, testCase "ExitLocal" (testExitLocal testtrans)
, testCase "ExitRemote" (testExitRemote testtrans)
, testCase "RegistryMonitoring" (testRegistryMonitoring testtrans)
, testCase "TextCallLocal" (testCallLocal testtrans)
-- Unsafe Primitives
, testCase "TestUnsafeSend" (testUnsafeSend testtrans)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module Control.Distributed.Process.Tests.Internal.Utils
-- ping !
, Ping(Ping)
, ping
, pause
, shouldBe
, shouldMatch
, shouldContain
Expand Down Expand Up @@ -78,10 +79,10 @@ import Control.Distributed.Process.Node
import Control.Distributed.Process.Serializable()

import Control.Exception (AsyncException(ThreadKilled), SomeException)
import Control.Monad (forever)
import Control.Monad (forever, void)
import Control.Monad.STM (atomically)
import Control.Rematch hiding (match)
import Control.Rematch.Run
import Control.Rematch.Run
import Data.Binary
import Data.Typeable (Typeable)

Expand All @@ -107,10 +108,18 @@ data TestProcessControl = Stop | Go | Report ProcessId

instance Binary TestProcessControl where

data Private = Private
deriving (Typeable, Generic)
instance Binary Private where

-- | Does exactly what it says on the tin, doing so in the @Process@ monad.
noop :: Process ()
noop = return ()

pause :: Int -> Process ()
pause delay =
void $ receiveTimeout delay [ match (\Private -> return ()) ]

synchronisedAssertion :: Eq a
=> String
-> LocalNode
Expand Down Expand Up @@ -229,4 +238,3 @@ tryForkProcess :: LocalNode -> Process () -> IO ProcessId
tryForkProcess node p = do
tid <- liftIO myThreadId
forkProcess node $ catch p (\e -> liftIO $ throwTo tid (e::SomeException))

Loading