{"action":"opened","issue":{"url":"https://api.github.com/repos/lagom/lagom/issues/68","repository_url":"https://api.github.com/repos/lagom/lagom","labels_url":"https://api.github.com/repos/lagom/lagom/issues/68/labels{/name}","comments_url":"https://api.github.com/repos/lagom/lagom/issues/68/comments","events_url":"https://api.github.com/repos/lagom/lagom/issues/68/events","html_url":"https://github.com/lagom/lagom/issues/68","id":144848510,"number":68,"title":"sbt reload when Cassandra is running results in exception","user":{"login":"dotta","id":703748,"avatar_url":"https://avatars.githubusercontent.com/u/703748?v=3","gravatar_id":"","url":"https://api.github.com/users/dotta","html_url":"https://github.com/dotta","followers_url":"https://api.github.com/users/dotta/followers","following_url":"https://api.github.com/users/dotta/following{/other_user}","gists_url":"https://api.github.com/users/dotta/gists{/gist_id}","starred_url":"https://api.github.com/users/dotta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotta/subscriptions","organizations_url":"https://api.github.com/users/dotta/orgs","repos_url":"https://api.github.com/users/dotta/repos","events_url":"https://api.github.com/users/dotta/events{/privacy}","received_events_url":"https://api.github.com/users/dotta/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/lagom/lagom/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/lagom/lagom/labels/development-environment","name":"development-environment","color":"fef2c0"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-03-31T09:57:26Z","updated_at":"2016-03-31T09:57:26Z","closed_at":null,"body":"When manually starting Cassandra, if a sbt `reload` is performed we should stop Cassandra, or otherwise we will loose the reference to the process running it.\r\n\r\nWe should add some hooks into the sbt lifecycle to clean up on reload. We also need to be very careful to ensure all stop hooks are removed on reload, as stop hooks are a hotspot for classloader leaks.\r\n\r\nHere is how to reproduce the problem:\r\n\r\n```\r\n> lagomCassandraStart\r\nStarting embedded Cassandra server.......\r\nCassandra server running @ 127.0.0.1:4000\r\n[success] Total time: 4 s, completed Feb 5, 2016 8:56:20 AM\r\n> reload\r\n...\r\n> lagomCassandraStart\r\n> 2016-02-05 08:56:34,464 ERROR org.apache.cassandra.service.CassandraDaemon - Error starting local jmx server: \r\njava.rmi.server.ExportException: Port already in use: 4099; nested exception is: \r\n    java.net.BindException: Address already in use\r\n    at sun.rmi.transport.tcp.TCPTransport.listen(TCPTransport.java:341) ~[na:1.8.0_60]\r\n    at sun.rmi.transport.tcp.TCPTransport.exportObject(TCPTransport.java:249) ~[na:1.8.0_60]\r\n    at sun.rmi.transport.tcp.TCPEndpoint.exportObject(TCPEndpoint.java:411) ~[na:1.8.0_60]\r\n    at sun.rmi.transport.LiveRef.exportObject(LiveRef.java:147) ~[na:1.8.0_60]\r\n    at sun.rmi.server.UnicastServerRef.exportObject(UnicastServerRef.java:208) ~[na:1.8.0_60]\r\n    at sun.rmi.registry.RegistryImpl.setup(RegistryImpl.java:152) ~[na:1.8.0_60]\r\n    at sun.rmi.registry.RegistryImpl.<init>(RegistryImpl.java:112) ~[na:1.8.0_60]\r\n    at java.rmi.registry.LocateRegistry.createRegistry(LocateRegistry.java:239) ~[na:1.8.0_60]\r\n    at org.apache.cassandra.service.CassandraDaemon.maybeInitJmx(CassandraDaemon.java:120) [cassandra-all-3.0.2.jar:3.0.2]\r\n    at org.apache.cassandra.service.CassandraDaemon.setup(CassandraDaemon.java:188) [cassandra-all-3.0.2.jar:3.0.2]\r\n    at org.apache.cassandra.service.CassandraDaemon.activate(CassandraDaemon.java:549) [cassandra-all-3.0.2.jar:3.0.2]\r\n    at akka.persistence.cassandra.testkit.CassandraLauncher$.start(CassandraLauncher.scala:103) [akka-persistence-cassandra_2.11-0.8.jar:0.8]\r\n    at akka.persistence.cassandra.testkit.CassandraLauncher$.main(CassandraLauncher.scala:46) [akka-persistence-cassandra_2.11-0.8.jar:0.8]\r\n    at akka.persistence.cassandra.testkit.CassandraLauncher.main(CassandraLauncher.scala) [akka-persistence-cassandra_2.11-0.8.jar:0.8]\r\nCaused by: java.net.BindException: Address already in use\r\n    at java.net.PlainSocketImpl.socketBind(Native Method) ~[na:1.8.0_60]\r\n    at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:387) ~[na:1.8.0_60]\r\n    at java.net.ServerSocket.bind(ServerSocket.java:375) ~[na:1.8.0_60]\r\n    at java.net.ServerSocket.<init>(ServerSocket.java:237) ~[na:1.8.0_60]\r\n    at javax.net.DefaultServerSocketFactory.createServerSocket(ServerSocketFactory.java:231) ~[na:1.8.0_60]\r\n    at org.apache.cassandra.utils.RMIServerSocketFactoryImpl.createServerSocket(RMIServerSocketFactoryImpl.java:13) ~[cassandra-all-3.0.2.jar:3.0.2]\r\n    at sun.rmi.transport.tcp.TCPEndpoint.newServerSocket(TCPEndpoint.java:666) ~[na:1.8.0_60]\r\n    at sun.rmi.transport.tcp.TCPTransport.listen(TCPTransport.java:330) ~[na:1.8.0_60]\r\n    ... 13 common frames omitted\r\nException (java.lang.IllegalStateException) encountered during startup: Failed to bind port 4000 on 127.0.0.1.\r\n2016-02-05 08:56:35,170 ERROR org.apache.cassandra.service.CassandraDaemon - Exception encountered during startup\r\njava.lang.IllegalStateException: Failed to bind port 4000 on 127.0.0.1.\r\n    at org.apache.cassandra.transport.Server.start(Server.java:166) ~[cassandra-all-3.0.2.jar:3.0.2]\r\n    at java.util.Collections$SingletonSet.forEach(Collections.java:4767) ~[na:1.8.0_60]\r\n    at org.apache.cassandra.service.NativeTransportService.start(NativeTransportService.java:128) ~[cassandra-all-3.0.2.jar:3.0.2]\r\n    at org.apache.cassandra.service.CassandraDaemon.startNativeTransport(CassandraDaemon.java:597) ~[cassandra-all-3.0.2.jar:3.0.2]\r\n    at org.apache.cassandra.service.CassandraDaemon.start(CassandraDaemon.java:459) ~[cassandra-all-3.0.2.jar:3.0.2]\r\n    at org.apache.cassandra.service.CassandraDaemon.activate(CassandraDaemon.java:564) ~[cassandra-all-3.0.2.jar:3.0.2]\r\n    at akka.persistence.cassandra.testkit.CassandraLauncher$.start(CassandraLauncher.scala:103) [akka-persistence-cassandra_2.11-0.8.jar:0.8]\r\n    at akka.persistence.cassandra.testkit.CassandraLauncher$.main(CassandraLauncher.scala:46) [akka-persistence-cassandra_2.11-0.8.jar:0.8]\r\n    at akka.persistence.cassandra.testkit.CassandraLauncher.main(CassandraLauncher.scala) [akka-persistence-cassandra_2.11-0.8.jar:0.8]\r\njava.lang.IllegalStateException: Failed to bind port 4000 on 127.0.0.1.\r\n    at org.apache.cassandra.transport.Server.start(Server.java:166)\r\n    at java.util.Collections$SingletonSet.forEach(Collections.java:4767)\r\n    at org.apache.cassandra.service.NativeTransportService.start(NativeTransportService.java:128)\r\n    at org.apache.cassandra.service.CassandraDaemon.startNativeTransport(CassandraDaemon.java:597)\r\n    at org.apache.cassandra.service.CassandraDaemon.start(CassandraDaemon.java:459)\r\n    at org.apache.cassandra.service.CassandraDaemon.activate(CassandraDaemon.java:564)\r\n    at akka.persistence.cassandra.testkit.CassandraLauncher$.start(CassandraLauncher.scala:103)\r\n    at akka.persistence.cassandra.testkit.CassandraLauncher$.main(CassandraLauncher.scala:46)\r\n    at akka.persistence.cassandra.testkit.CassandraLauncher.main(CassandraLauncher.scala)\r\n2016-02-05 08:56:35,171 ERROR org.apache.cassandra.service.CassandraDaemon - Exception in thread Thread[main,5,main]\r\njava.lang.RuntimeException: Exception encountered during startup\r\n    at org.apache.cassandra.service.CassandraDaemon.exitOrFail(CassandraDaemon.java:686) ~[cassandra-all-3.0.2.jar:3.0.2]\r\n    at org.apache.cassandra.service.CassandraDaemon.activate(CassandraDaemon.java:579) ~[cassandra-all-3.0.2.jar:3.0.2]\r\n    at akka.persistence.cassandra.testkit.CassandraLauncher$.start(CassandraLauncher.scala:103) ~[akka-persistence-cassandra_2.11-0.8.jar:0.8]\r\n    at akka.persistence.cassandra.testkit.CassandraLauncher$.main(CassandraLauncher.scala:46) ~[akka-persistence-cassandra_2.11-0.8.jar:0.8]\r\n    at akka.persistence.cassandra.testkit.CassandraLauncher.main(CassandraLauncher.scala) ~[akka-persistence-cassandra_2.11-0.8.jar:0.8]\r\nCaused by: java.lang.IllegalStateException: Failed to bind port 4000 on 127.0.0.1.\r\n    at org.apache.cassandra.transport.Server.start(Server.java:166) ~[cassandra-all-3.0.2.jar:3.0.2]\r\n    at java.util.Collections$SingletonSet.forEach(Collections.java:4767) ~[na:1.8.0_60]\r\n    at org.apache.cassandra.service.NativeTransportService.start(NativeTransportService.java:128) ~[cassandra-all-3.0.2.jar:3.0.2]\r\n    at org.apache.cassandra.service.CassandraDaemon.startNativeTransport(CassandraDaemon.java:597) ~[cassandra-all-3.0.2.jar:3.0.2]\r\n    at org.apache.cassandra.service.CassandraDaemon.start(CassandraDaemon.java:459) ~[cassandra-all-3.0.2.jar:3.0.2]\r\n    at org.apache.cassandra.service.CassandraDaemon.activate(CassandraDaemon.java:564) ~[cassandra-all-3.0.2.jar:3.0.2]\r\n    ... 3 common frames omitted"}}