0

I'm requesting some data from a remote database, using the c3p0 pool of connections approach. I can nicely retrieve all the data I need, but for some reason, that apparently seems to be related with network socket, I'm getting the java.net.SocketException according to this stack trace:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1137)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3697)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3586)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4131)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2597)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2758)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2820)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2769)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1569)
at com.mchange.v2.c3p0.impl.NewProxyStatement.executeQuery(NewProxyStatement.java:327)
at MemsqlRequester.run(MemsqlRequester.java:28)
Caused by: java.net.SocketException: Connection timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:170)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:112)
at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:159)
at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:187)
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3140)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3597)
... 9 more
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 0
at java.util.Vector.get(Vector.java:748)
at GraphTransformer$$anonfun$getTxInformationList$1.apply$mcVI$sp(GraphTransformer.scala:38)
at scala.collection.immutable.Range.foreach$mVc$sp(Range.scala:141)
at GraphTransformer.getTxInformationList(GraphTransformer.scala:37)
at GraphTransformer.getFeaturesTx(GraphTransformer.scala:62)
at GraphTransformer.getFeatures(GraphTransformer.scala:327)
at GraphDatasetBuilder.lambda$publishGraphFeaturesFromMemsql$13(GraphDatasetBuilder.java:62)
at java.util.Vector.forEach(Vector.java:1249)
at GraphDatasetBuilder.publishGraphFeaturesFromMemsql(GraphDatasetBuilder.java:59)
at GraphDatasetBuilder.main(GraphDatasetBuilder.java:124)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:674)
at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:180)
at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:205)
at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:120)
at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)

Basically the code snippet where I do the statement calls to retrieve my data from the remote dataset are below:

try {
   ...
   Statement stmt = connection.createStatement();
   rs = stmt.executeQuery(this.queryList.get(queryIndex)); // According to the stack trace, here is where I'm getting the SocketException
   ...
} catch (SQLException ex) {
    ex.printStackTrace();
}

The problem is that I can add any catch clause surrounding this code because it tells me no SocketException is being thrown. Basically my question is what's going wrong here, considering that apparently I can't handle a SocketException in my code as stated in the stack trace.

4
  • You left out the first line of the stack trace. The one with the exception in it. And the message. That tells you what the problem is. Commented Jan 16, 2016 at 23:54
  • So the exception is an ArrayIndexOutOfBoundsException Commented Jan 17, 2016 at 0:01
  • No, that is a subsequent exception, and if you're asking about that you shouldn't be, it is a trivial programming error. You still haven't provided the first line of the original exception. The one you're actually asking about, or should be. Hint: it is an SQLException, or something derived from one. Commented Jan 17, 2016 at 0:23
  • Hey @EJP, it is a CommunicationsException Commented Jan 17, 2016 at 1:53

1 Answer 1

1

The stacktrace that you have posted is not complete, we cannot see what exception has been thrown.

If you cannot catch the SocketException, I presume that the exception that you are receiving is a different one.

The SocketException is caught by the driver and re-thrown as a different exception. The SocketException that you can see in the stack trace is only the "caused by", that is the original exception that has been caught.

Update

You cannot catch The SocketException because it is not the exception that you receive. Please paste the full stack trace.

It seems that the ArrayIndexOutOfBoundsException is a new exception. I can be wrong, but I do not think that the driver would throw an ArrayIndexOutOfBoundsException. This exception seems thrown by spark.

I am not absolutely sure, but it seems to me that:

1) There is a network problem and you cannot access the database and open the connection;

2) A SocketException is thrown in the driver;

3) This Exception is caught and re-thrown as a different exception (the stack trace is incomplete and the exception thrown is not visible yet, but I guess that is a CommunicationsException);

4) As a consequence, the spark's code that is trying to read a graph fails and throws the ArrayIndexOutOfBoundsException;

Sign up to request clarification or add additional context in comments.

5 Comments

The exception is ArrayIndexOutOfBoundsException, but yes, the root cause is that SocketException that I'd like to catch if that's possible
I think that you should catch the exception CommunicationsException (if I am not wrong this is the exception that the driver throws).
@SauloRicci The root cause of an ArrayIndexOutOfBoundsException is not and can never be a SocketException.
@MarcoAltieri yes, exactly is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure. And yes, you got the exactly scenario
Ok. Thanks for the update. If you do not need other info and you think that the answer was right, could you set the answer as accepted ? :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.