title: Exception in thread "main" java.lang.reflect.UndeclaredThrowableException on worker node in spark standalone mode
body: <p>I am getting the following error when trying to submit spark job using spark-submit. I am unable to understand the error what exactly it's asking for.</p>
  <p>It is failing at below line.</p>
  <pre><code>spark.read.format(&quot;com.mongodb.spark.sql.DefaultSource&quot;).
            option(&quot;spark.mongodb.input.partitioner&quot;, &quot;MongoSinglePartitioner&quot;).
            option(&quot;uri&quot;, connectionString).
            load()
  </code></pre>
  <p>Here is my spark submit command:</p>
  <pre><code>spark-submit \
   --class com.sparkTutorial.input \
   --deploy-mode cluster \
   --master &quot;spark://master-node:7077&quot; \
   --packages com.microsoft.sqlserver:mssql-jdbc:7.4.1.jre11 \
   --packages org.mongodb.spark:mongo-spark-connector_2.12:3.0.1 \
   target/scala-2.12/sql-mongo-validation-assembly-0.1.jar
  </code></pre>
  <p>Logs on a worker node.</p>
  <pre><code>Spark Executor Command: &quot;/usr/local/openjdk-11/bin/java&quot; &quot;-cp&quot; &quot;/opt/spark/conf/:/opt/spark/jars/*&quot; &quot;-Xmx2048M&quot; &quot;-Dspark.driver.port=36881&quot; &quot;-Dspark.rpc.askTimeout=10s&quot; &quot;org.apache.spark.executor.CoarseGrainedExecutorBackend&quot; &quot;--driver-url&quot; &quot;spark://CoarseGrainedScheduler@localhost:36881&quot; &quot;--executor-id&quot; &quot;36&quot; &quot;--hostname&quot; &quot;172.22.0.5&quot; &quot;--cores&quot; &quot;2&quot; &quot;--app-id&quot; &quot;app-20210907192950-0004&quot; &quot;--worker-url&quot; &quot;spark://Worker@172.22.0.5:46711&quot;
  ========================================
  
  Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties
  21/09/07 19:30:30 INFO CoarseGrainedExecutorBackend: Started daemon with process name: 22087@bbc2066271a2
  21/09/07 19:30:30 INFO SignalUtils: Registering signal handler for TERM
  21/09/07 19:30:30 INFO SignalUtils: Registering signal handler for HUP
  21/09/07 19:30:30 INFO SignalUtils: Registering signal handler for INT
  WARNING: An illegal reflective access operation has occurred
  WARNING: Illegal reflective access by org.apache.spark.unsafe.Platform (file:/opt/spark/jars/spark-unsafe_2.12-3.1.2.jar) to constructor java.nio.DirectByteBuffer(long,int)
  WARNING: Please consider reporting this to the maintainers of org.apache.spark.unsafe.Platform
  WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
  WARNING: All illegal access operations will be denied in a future release
  21/09/07 19:30:31 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
  21/09/07 19:30:31 INFO SecurityManager: Changing view acls to: root
  21/09/07 19:30:31 INFO SecurityManager: Changing modify acls to: root
  21/09/07 19:30:31 INFO SecurityManager: Changing view acls groups to: 
  21/09/07 19:30:31 INFO SecurityManager: Changing modify acls groups to: 
  21/09/07 19:30:31 INFO SecurityManager: SecurityManager: authentication disabled; ui acls disabled; users  with view permissions: Set(root); groups with view permissions: Set(); users  with modify permissions: Set(root); groups with modify permissions: Set()
  Exception in thread &quot;main&quot; java.lang.reflect.UndeclaredThrowableException
      at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1748)
      at org.apache.spark.deploy.SparkHadoopUtil.runAsSparkUser(SparkHadoopUtil.scala:61)
      at org.apache.spark.executor.CoarseGrainedExecutorBackend$.run(CoarseGrainedExecutorBackend.scala:393)
      at org.apache.spark.executor.CoarseGrainedExecutorBackend$.main(CoarseGrainedExecutorBackend.scala:382)
      at org.apache.spark.executor.CoarseGrainedExecutorBackend.main(CoarseGrainedExecutorBackend.scala)
  Caused by: org.apache.spark.SparkException: Exception thrown in awaitResult: 
      at org.apache.spark.util.ThreadUtils$.awaitResult(ThreadUtils.scala:301)
      at org.apache.spark.rpc.RpcTimeout.awaitResult(RpcTimeout.scala:75)
      at org.apache.spark.rpc.RpcEnv.setupEndpointRefByURI(RpcEnv.scala:101)
      at org.apache.spark.executor.CoarseGrainedExecutorBackend$.$anonfun$run$9(CoarseGrainedExecutorBackend.scala:413)
      at scala.runtime.java8.JFunction1$mcVI$sp.apply(JFunction1$mcVI$sp.java:23)
      at scala.collection.TraversableLike$WithFilter.$anonfun$foreach$1(TraversableLike.scala:877)
      at scala.collection.immutable.Range.foreach(Range.scala:158)
      at scala.collection.TraversableLike$WithFilter.foreach(TraversableLike.scala:876)
      at org.apache.spark.executor.CoarseGrainedExecutorBackend$.$anonfun$run$7(CoarseGrainedExecutorBackend.scala:411)
      at org.apache.spark.deploy.SparkHadoopUtil$$anon$1.run(SparkHadoopUtil.scala:62)
      at org.apache.spark.deploy.SparkHadoopUtil$$anon$1.run(SparkHadoopUtil.scala:61)
      at java.base/java.security.AccessController.doPrivileged(Native Method)
      at java.base/javax.security.auth.Subject.doAs(Unknown Source)
      at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1730)
      ... 4 more
  Caused by: java.io.IOException: Failed to connect to localhost/127.0.0.1:36881
      at org.apache.spark.network.client.TransportClientFactory.createClient(TransportClientFactory.java:287)
      at org.apache.spark.network.client.TransportClientFactory.createClient(TransportClientFactory.java:218)
      at org.apache.spark.network.client.TransportClientFactory.createClient(TransportClientFactory.java:230)
      at org.apache.spark.rpc.netty.NettyRpcEnv.createClient(NettyRpcEnv.scala:204)
      at org.apache.spark.rpc.netty.Outbox$$anon$1.call(Outbox.scala:202)
      at org.apache.spark.rpc.netty.Outbox$$anon$1.call(Outbox.scala:198)
      at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
      at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at java.base/java.lang.Thread.run(Unknown Source)
  Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: localhost/127.0.0.1:36881
  Caused by: java.net.ConnectException: Connection refused
      at java.base/sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
      at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(Unknown Source)
      at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:330)
      at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:334)
      at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:702)
      at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650)
      at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576)
      at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
      at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
      at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
      at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
      at java.base/java.lang.Thread.run(Unknown Source)
  </code></pre>