java.net.SocketException: Permission denied

Raymond Raymond event 2021-01-02 visibility 2,055
more_vert

About the error

When trying to start Hadoop DFS services in WSL (Windows Subsystem for Linux), it failed with the following error:

2021-01-01 21:13:37,650 INFO org.apache.hadoop.http.HttpServer2: HttpServer.start() threw a non Bind IOException
java.net.BindException: Port in use: 0.0.0.0:9870
	at org.apache.hadoop.http.HttpServer2.constructBindException(HttpServer2.java:1292)
	at org.apache.hadoop.http.HttpServer2.bindForSinglePort(HttpServer2.java:1314)
	at org.apache.hadoop.http.HttpServer2.openListeners(HttpServer2.java:1373)
	at org.apache.hadoop.http.HttpServer2.start(HttpServer2.java:1223)
	at org.apache.hadoop.hdfs.server.namenode.NameNodeHttpServer.start(NameNodeHttpServer.java:170)
	at org.apache.hadoop.hdfs.server.namenode.NameNode.startHttpServer(NameNode.java:946)
	at org.apache.hadoop.hdfs.server.namenode.NameNode.initialize(NameNode.java:757)
	at org.apache.hadoop.hdfs.server.namenode.NameNode.<init>(NameNode.java:1014)
	at org.apache.hadoop.hdfs.server.namenode.NameNode.<init>(NameNode.java:987)
	at org.apache.hadoop.hdfs.server.namenode.NameNode.createNameNode(NameNode.java:1756)
	at org.apache.hadoop.hdfs.server.namenode.NameNode.main(NameNode.java:1821)
Caused by: java.net.SocketException: Permission denied
	at sun.nio.ch.Net.bind0(Native Method)
	at sun.nio.ch.Net.bind(Net.java:433)
	at sun.nio.ch.Net.bind(Net.java:425)
	at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
	at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
	at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:342)
	at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:307)
	at org.apache.hadoop.http.HttpServer2.bindListener(HttpServer2.java:1279)
	at org.apache.hadoop.http.HttpServer2.bindForSinglePort(HttpServer2.java:1310)
	... 9 more
2021-01-01 21:13:37,655 INFO org.apache.hadoop.metrics2.impl.MetricsSystemImpl: Stopping NameNode metrics system...
2021-01-01 21:13:37,656 INFO org.apache.hadoop.metrics2.impl.MetricsSystemImpl: NameNode metrics system stopped.
2021-01-01 21:13:37,656 INFO org.apache.hadoop.metrics2.impl.MetricsSystemImpl: NameNode metrics system shutdown complete.
2021-01-01 21:13:37,656 ERROR org.apache.hadoop.hdfs.server.namenode.NameNode: Failed to start namenode.
java.net.BindException: Port in use: 0.0.0.0:9870
	at org.apache.hadoop.http.HttpServer2.constructBindException(HttpServer2.java:1292)
	at org.apache.hadoop.http.HttpServer2.bindForSinglePort(HttpServer2.java:1314)
	at org.apache.hadoop.http.HttpServer2.openListeners(HttpServer2.java:1373)
	at org.apache.hadoop.http.HttpServer2.start(HttpServer2.java:1223)
	at org.apache.hadoop.hdfs.server.namenode.NameNodeHttpServer.start(NameNodeHttpServer.java:170)
	at org.apache.hadoop.hdfs.server.namenode.NameNode.startHttpServer(NameNode.java:946)
	at org.apache.hadoop.hdfs.server.namenode.NameNode.initialize(NameNode.java:757)
	at org.apache.hadoop.hdfs.server.namenode.NameNode.<init>(NameNode.java:1014)
	at org.apache.hadoop.hdfs.server.namenode.NameNode.<init>(NameNode.java:987)
	at org.apache.hadoop.hdfs.server.namenode.NameNode.createNameNode(NameNode.java:1756)
	at org.apache.hadoop.hdfs.server.namenode.NameNode.main(NameNode.java:1821)
Caused by: java.net.SocketException: Permission denied
	at sun.nio.ch.Net.bind0(Native Method)
	at sun.nio.ch.Net.bind(Net.java:433)
	at sun.nio.ch.Net.bind(Net.java:425)
	at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
	at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
	at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:342)
	at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:307)
	at org.apache.hadoop.http.HttpServer2.bindListener(HttpServer2.java:1279)
	at org.apache.hadoop.http.HttpServer2.bindForSinglePort(HttpServer2.java:1310)
	... 9 more
2021-01-01 21:13:37,659 INFO org.apache.hadoop.util.ExitUtil: Exiting with status 1: java.net.BindException: Port in use: 0.0.0.0:9870
2021-01-01 21:13:37,663 INFO org.apache.hadoop.hdfs.server.namenode.NameNode: SHUTDOWN_MSG: 

Debug

The following actions were conducted but nothing helps:

  • Use the following command in Command Prompt in Windows 10 (host) and the result is empty i.e. port is not used.
    netstat -ano |grep 9870
  • Modified HDFS configuration file to use different ports. Nothing
  • Confirmed HDFS namenode ports are not privileged ports. 
  • (For Windows incl. WSL) Follow this page to check if the port numbers are reserved by Hyper-V if it is enabled on your system: Resolution - Cannot Start MySQL on WSL.

Resolution

After digging through, finally the issue was fixed via the following approach:

  • Run WSL as Administrator
    20210102215652-image.png
  • Then start HDFS services in the terminal.
More from Kontext
comment Comments
H hedmond john

hedmond access_time 3 years ago link more_vert

Your Java socket shows SocketTimeoutException means that it takes too long to get respond from other device and your request expires before getting response. This exception is occurring on following condition.

  • Server is slow and default timeout is less, so just put timeout value according to you.
  • Server is working fine but timeout value is for less time. so change the timeout value.

Solution: A java developer can pre-set the timeout option for both client and server operations.

From Client side:

Socket socket = new Socket();

SocketAddress socketAddress = new InetSocketAddress(host, port);

socket.connect(socketAddress, 12000); //12000 are milli seconds


From Server side:

ServerSocket serverSocket = new new ServerSocket(port);

serverSocket.setSoTimeout(12000);



Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts