I've been plagued for a week with connection errors whenever I run my code outside of my local machine.
The connection errors are because carmine is connecting to localhost, no matter what I do. Here is the full output from a repl session, from my ns store.core, which requires [taoensso.carmine :as redis]:
(def conn
{:pool {}
:spec {:url "redis://redistogo:[password]#chubb.redistogo.com:9836/"}})
#'store.core/conn
store.core=> (redis/wcar conn (redis/hget 1 2))
java.net.ConnectException: Connection refused (Connection refused)
clojure.lang.ExceptionInfo: Carmine connection error
[enable local redis in another terminal]
store.core=> (redis/wcar conn (redis/hget 1 2))
"3"
^ this is now connecting to my local redis, despite `conn` pointing to redistogo.
What am I doing wrong? This usage seems exactly as carmine.clj#L28 suggests!
Answer from the author of carmine
Could you possibly try with :uri instead of :url?
source
FML
Related
Starting repl using:
lein repl :headless :port 4242
When I try to connect VIA cider connect I get the following error:
Connection closed unexpectedly (connection broken by remote peer)
When I try to connect VIA:
lein repl :connect 4242
I get the following error:
SocketException The transport's socket appears to have lost its connection to the nREPL server
clojure.tools.nrepl.transport/bencode/fn--5154/fn--5155 (transport.clj:95)
clojure.tools.nrepl.transport/bencode/fn--5154 (transport.clj:95)
clojure.tools.nrepl.transport/fn-transport/fn--5126 (transport.clj:42)
clojure.core/binding-conveyor-fn/fn--4676 (core.clj:1938)
java.util.concurrent.FutureTask.run (FutureTask.java:266)
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
java.lang.Thread.run (Thread.java:748)
Bye for now!
By default nrepl listens for connections only from the same computer. It does this by "binding" its listener to the IP address of the loopback network 127.0.0.1. If you want it to listen for connections from anywhere you can either bind it to 0.0.0.0 which is the any network address, or the address of a specific adapter.
It looks like I needed to specify the host as 0.0.0.0 e.g.
lein repl :headless :host 0.0.0.0 :port 4242
When I just do lein repl it works, but when I try to connect to a host I get a refusing to connect error.
Connecting to nREPL at 127.0.0.1:7000
ConnectException Connection refused (Connection refused)
java.net.PlainSocketImpl.socketConnect (PlainSocketImpl.java:-2)
java.net.AbstractPlainSocketImpl.doConnect (AbstractPlainSocketImpl.java:400)
java.net.AbstractPlainSocketImpl.connectToAddress (AbstractPlainSocketImpl.java:243)
java.net.AbstractPlainSocketImpl.connect (AbstractPlainSocketImpl.java:225)
java.net.SocksSocketImpl.connect (SocksSocketImpl.java:402)
java.net.Socket.connect (Socket.java:591)
java.net.Socket.connect (Socket.java:540)
java.net.Socket.<init> (Socket.java:436)
java.net.Socket.<init> (Socket.java:213)
clojure.tools.nrepl/connect (nrepl.clj:184)
clojure.tools.nrepl/connect (nrepl.clj:174)
clojure.core/apply (core.clj:646)
Bye for now!
I have tried messing with my /etc/hosts:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
But changing it did not help.
Settings:
MacOS 10.13.2
Leiningen 2.8.1 on Java 9.0.1 Java HotSpot(TM) 64-Bit Server VM
Running lein repl will start its own nREPL and connect to that. Specifying :connect 7000 won't start a REPL—it expects one to already be running on that port.
$ lein repl
nREPL server started on port 57535 on host 127.0.0.1 - nrepl://127.0.0.1:57535
REPL-y 0.3.7, nREPL 0.2.12
In a separate session you should be able to connect to your other/running REPL:
$ lein repl :connect 57535
Connecting to nREPL at 127.0.0.1:57535
REPL-y 0.3.7, nREPL 0.2.12
I'm getting the following warning when running Aleph (which uses Netty) as a websever inside a Docker container:
WARNING: Failed to find a usable hardware address from the network interfaces; using random bytes: 75:62:7f:9b:c6:52:63:4b
I'm starting the server using:
(defn -main [& args]
(http/start-server app {:port 3000}))
And I've also tried:
(defn -main [& args]
(http/start-server app {:socket-address (java.net.InetSocketAddress. "0.0.0.0" 3000)}))
but still I get the same warning.
The warning only happens inside a docker container. I can run the server in my host without the warning. I also won't get the warning if when I run the container I use docker run --net host webserver.
The really weird thing is, despite the warning everything looks to be running fine. The correct ports are bound and the server is running correctly. Does anyone have any idea why I get this warning?
I have trouble setting up Datomic with Heroku Postgres. First of all I have this successfully installed
[com.datomic/datomic-pro "0.9.5206" :exclusions [joda-time]]
My sql-transactor.properties file looks like this:
protocol=sql
host=localhost
port=4334
license-key=<MY_LICENSE_KEY>
sql-url=jdbc:postgresql://ec2-54-204-3-200.compute-1.amazonaws.com:5432/<MY_HEROKU_DB_NAME>
sql-user=<MY_USER>
sql-password=<MY_PASS>
sql-driver-params=ssl=true;sslfactory=org.postgresql.ssl.NonValidatingFactory
When I try to run transactor from downloaded datomic-pro folder as:
bin/transactor /path/to/folder/sql-transactor.properties
It gives following output:
Launching with Java options -server -Xms1g -Xmx1g -XX:+UseG1GC -XX:MaxGCPauseMillis=50
Starting datomic:sql://<DB-NAME>?jdbc:postgresql://ec2-54-204-3-200.compute-1.amazonaws.com:5432/<MY_HEROKU_DB_NAME>?user=<MY_USER>&password=<MY_PASS>&ssl=true;sslfactory=org.postgresql.ssl.NonValidatingFactory, you may need to change the user and password parameters to work with your jdbc driver ...
System started datomic:sql://<DB-NAME>?jdbc:postgresql://ec2-54-204-3-200.compute-1.amazonaws.com:5432/<MY_HEROKU_DB_NAME>?user=<MY_USER>&password=<MY_PASS>&ssl=true;sslfactory=org.postgresql.ssl.NonValidatingFactory, you may need to change the user and password parameters to work with your jdbc driver
NOTE: The <DB-NAME> in the output is literally <DB-NAME>. It's not my placeholder. I think this might be a mistake.
Now when I try in clojure:
(def uri "datomic:sql://<MY_HEROKU_DB_NAME>?jdbc:postgresql://localhost:5432/<MY_HEROKU_DB_NAME>")
(def conn (datomic.api/connect uri))
It gives error:
java.net.ConnectException: Connection refused
org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
java.util.concurrent.ExecutionException: org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
clojure.lang.Compiler$CompilerException: java.util.concurrent.ExecutionException: org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections., compiling:(server.clj:40:11)
Anybody any ideas?
EDIT: I forgot to mention that I already did steps from http://docs.datomic.com/storage.html about bin/sql/postgres-table script
Running Leiningen 2.3.4 on Java 1.7.0_21 Java HotSpot(TM) 64-Bit Server VM
I am having trouble connecting to an nREPL server.
I setup a new project using lein new luminus, and then added a dependency to drawbridge ([com.cemerick/drawbridge "0.0.6"]).
I added a handler route for the repl as follows (based on https://devcenter.heroku.com/articles/debugging-clojure):
(def drawbridge-handler
(-> (cemerick.drawbridge/ring-handler)
(wrap-keyword-params)
(wrap-nested-params)
(wrap-params)
(wrap-session)))
(defn wrap-drawbridge [handler]
(fn [req]
(if (= "/repl" (:uri req))
(drawbridge-handler req)
(handler req))))
And added wrap-drawbridge to my middlewares.
I then start the server using
lein ring server-headless
The connection seems to be working well because performing a GET request on http:localhost:3000/repl yields a response: ["[\n","\n]"]
But I can't connect to the REPL:
> lein repl :connect 0.0.0.0:3000/repl
Connecting to nREPL at 0.0.0.0:3000/repl
And, after some time:
SocketException The transport's socket appears to have lost its connection to the nREPL server
clojure.tools.nrepl.transport/bencode/fn--4287/fn--4288 (transport.clj:95)
clojure.tools.nrepl.transport/bencode/fn--4287 (transport.clj:95)
clojure.tools.nrepl.transport/fn-transport/fn--4261 (transport.clj:42)
clojure.core/binding-conveyor-fn/fn--4107 (core.clj:1836)
java.util.concurrent.FutureTask$Sync.innerRun (FutureTask.java:334)
java.util.concurrent.FutureTask.run (FutureTask.java:166)
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:615)
java.lang.Thread.run (Thread.java:722)
Bye for now!
Am I missing something?
Edit:
Added the following logging code to my handler:
(defn wrap-drawbridge [handler]
(fn [req]
(if (= "/repl" (:uri req))
(do (println "IN REPL ")
(drawbridge-handler req))
(handler req))))
When connecting with lein repl :connect http://localhost:3000/repl as suggested, I see the line IN REPL being printed in an infinite loop, on the servers console.
Not really a direct answer, but I've found that I was not approaching this problem the right way.
Luminus creates a project-name.repl namespace that should be used for interactive development.
I found that I could do what I wanted by adding to my project.clj
:repl-options {
:init-ns project-name.repl
:init (start-server)}
And then simply starting the server with lein repl.
Much simpler than setting up an nREPL middleware!
Have you made sure that there actually is a request entering your server (e.g. by printlining)?
However, my first guess would be that lein repl :connect behaves differently depending on whether you pass it an IP/Port pair or a fully-qualified URL. Since drawbridge seems to make nREPL accessible via HTTP I'd suggest you try:
lein repl :connect http://localhost:3000/repl
You need to add wrap-drawbridge at the first place in you middleware list.
If you do something like that
(def app (-> #'all-routes
wrap-drawbridge
...
...
...
))
It works like a charm.