telnet – "Connection closed by foreign host"

I want to setup an Apache Spark Cluster but I am not able to communicate from the worker machine to the master machine at port 7077 (where the Spark Master is running).

So I tried to telnet to the master from the worker machine and this is what I am seeing:

root@worker:~# telnet spark 7077
Trying 10.xx.xx.xx...
Connected to spark.
Escape character is '^]'.
Connection closed by foreign host.

The command terminated with “Connection closed by foreign host” immediately. It does not timeout or anything.

I verified that the the host is listening on the port and since telnet output shows “Connected to spark.” — this also means that the connection is successful.

What could be the reason for such behavior?
I am wondering if this closing of the connection could be the reason why I am not able to communicate from my worker machine to the master.

Asked By: Mor Eru


The process that is listening for connections on port 7077 is accepting the connection and then immediately closing the connection. The problem lies somewhere in that application’s code or configuration, not in the system itself.

Answered By: John

I just learned of an odd behaviour in some virtual servers, especially those that are run NAT. You connect to the port exposed by the virtual server to the outside; the server then tries to forward the connection to a target; the target refuses. So the NAT will close your connection with no message whatsoever. Pull your hair out trying to figure out what’s going on. This is very much like the previous answer; the source is the interaction in the virtual host itself.

The most likely cause is that someone is using the port, and the application running only accepts one connection at a time, and refuses any additional connections.

Answered By: Stephen Satchell

We came across this very error when trying to debug why email (through Python code) sending from a host was failing. It turned out to be due to the mail queue on the mail server being full for this particular host.

Answered By: pdp

The application has policy restrictions to connect only from localhost. Same “problem” with elasticsearch. You can check your app-config or you can make a tunnel. Do

ssh -N -L 7077: userxy@spark

then on your machine:

telnet 7077
Answered By: Max Mustermann
Categories: Answers Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.