pyspark is hanging while attempting to make URL requests in parallel - scala

I have an rdd of URLs and I want to make url requests in parallel. I am running get_menus with an rdd of url strings. Pyspark hangs when trying to collect(), take(), etc. on items.
def format_json(response, slug):
clean_response = str(response)[:-1]
clean_response += ", 'slug': '" + slug + "'}\n" # ', \"store-slug\": \"' + slug +'\"}'
clean_response = clean_response.replace("None", "null").replace("True", 'true').replace("False", "false")
return clean_response
def get_all(url, slug):
response = requests.get(url)
response = json.loads(response).get('data', {})
clean_response = format_json(response, slug)
return clean_response
def get_items(rdd_of_urls):
get_items_udf = udf(lambda x: get_all(x), StringType())
items = rdd_of_urls.map(get_items_udf)
return items
I see many GC allocation errors but don't know how to interpret them:
2019-08-21T18:40:04.666+0000: [GC (Allocation Failure) 2019-08-21T18:40:04.666+0000: [ParNew: 34369K->1837K(36864K), 0.0029907 secs] 127948K->95416K(186848K), 0.0030414 secs] [Times: user=0.01 sys=0.00, real=0.01 secs]
2019-08-21T18:40:04.951+0000: [GC (Allocation Failure) 2019-08-21T18:40:04.951+0000: [ParNew: 34605K->2576K(36864K), 0.0036551 secs] 128184K->96155K(186848K), 0.0037126 secs] [Times: user=0.02 sys=0.00, real=0.01 secs]

Related

About how to create a custom org.apache.spark.sql.types.StructType schema object starting from a json file programmatically

i have to create a custom org.apache.spark.sql.types.StructType schema object with the info from a json file, the json file can be anything, so i have parametriced it within a property file.
This is how it looks the property file:
//ruta al esquema del fichero output (por defecto se infiere el esquema del Parquet destino). Si existe, el esquema serĂ¡ en formato JSON, aplicable a DataFrame (ver StructType.fromJson)
schema.parquet=/Users/XXXX/Desktop/generated_schema.json
writing.mode=overwrite
separator=;
header=false
The file generated_schema.json looks like:
{"type" : "struct","fields" : [ {"name" : "codigo","type" : "string","nullable" : true}, {"name":"otro", "type":"string", "nullable":true}, {"name":"vacio", "type":"string", "nullable":true},{"name":"final","type":"string","nullable":true} ]}
So, this is how i thought that i can solve it:
val path: Path = new Path(mra_schema_parquet)
val fileSystem = path.getFileSystem(sc.hadoopConfiguration)
val inputStream: FSDataInputStream = fileSystem.open(path)
val schema_json = Stream.cons(inputStream.readLine(), Stream.continually( inputStream.readLine))
System.out.println("schema_json looks like " + schema_json.head)
val mySchemaStructType :DataType = DataType.fromJson(schema_json.head)
/*
After this line, mySchemaStructType have four StructFields objects inside it, the same than appears at schema_json
*/
logger.info(mySchemaStructType)
val myStructType = new StructType()
myStructType.add("mySchemaStructType",mySchemaStructType)
/*
After this line, myStructType have zero StructFields! here must be the bug, myStructType should have the four StructFields that represents the loaded schema json! this must be the error! but how can i construct the necessary StructType object?
*/
myDF = loadCSV(sqlContext, path_input_csv,separator,myStructType,header)
System.out.println("myDF.schema.json looks like " + myDF.schema.json)
inputStream.close()
df.write
.format("com.databricks.spark.csv")
.option("header", header)
.option("delimiter",delimiter)
.option("nullValue","")
.option("treatEmptyValuesAsNulls","true")
.mode(saveMode)
.parquet(pathParquet)
When the code runs the last line, .parquet(pathParquet), the exception happens:
**parquet.schema.InvalidSchemaException: Cannot write a schema with an empty group: message root {
}**
The output of this code is like this:
16/11/11 13:57:04 INFO AnotherCSVtoParquet$: The job started using this propertie file: /Users/aisidoro/Desktop/mra-csv-converter/parametrizacion.properties
16/11/11 13:57:05 INFO AnotherCSVtoParquet$: path_input_csv is /Users/aisidoro/Desktop/mra-csv-converter/cds_glcs.csv
16/11/11 13:57:05 INFO AnotherCSVtoParquet$: path_output_parquet is /Users/aisidoro/Desktop/output900000
16/11/11 13:57:05 INFO AnotherCSVtoParquet$: mra_schema_parquet is /Users/aisidoro/Desktop/mra-csv-converter/generated_schema.json
16/11/11 13:57:05 INFO AnotherCSVtoParquet$: writting_mode is overwrite
16/11/11 13:57:05 INFO AnotherCSVtoParquet$: separator is ;
16/11/11 13:57:05 INFO AnotherCSVtoParquet$: header is false
16/11/11 13:57:05 INFO AnotherCSVtoParquet$: ATTENTION! aplying mra_schema_parquet /Users/aisidoro/Desktop/mra-csv-converter/generated_schema.json
schema_json looks like {"type" : "struct","fields" : [ {"name" : "codigo","type" : "string","nullable" : true}, {"name":"otro", "type":"string", "nullable":true}, {"name":"vacio", "type":"string", "nullable":true},{"name":"final","type":"string","nullable":true} ]}
16/11/11 13:57:12 INFO AnotherCSVtoParquet$: StructType(StructField(codigo,StringType,true), StructField(otro,StringType,true), StructField(vacio,StringType,true), StructField(final,StringType,true))
16/11/11 13:57:13 INFO AnotherCSVtoParquet$: loadCSV. header is false, inferSchema is false pathCSV is /Users/aisidoro/Desktop/mra-csv-converter/cds_glcs.csv separator is ;
myDF.schema.json looks like {"type":"struct","fields":[]}
It should be that schema_json object and myDF.schema.json object should have the same content, shouldn't ? but it did not happen. I think this must launch the error.
Finally the job crushes with this exception:
**parquet.schema.InvalidSchemaException: Cannot write a schema with an empty group: message root {
}**
The fact is if i do not provide any json schema file, the job performs fine, but with this schema...
Can anybody help me? I just want to create some parquet files starting from a csv file and json schema file.
Thank you.
The dependencies are:
<spark.version>1.5.0-cdh5.5.2</spark.version>
<databricks.version>1.5.0</databricks.version>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.10</artifactId>
<version>${spark.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.databricks</groupId>
<artifactId>spark-csv_2.10</artifactId>
<version>${databricks.version}</version>
</dependency>
UPDATE
I can see that there is a open issue,
https://github.com/databricks/spark-csv/issues/61
Since you said Custom Schema, you can do something like this.
val schema = (new StructType).add("field1", StringType).add("field2", StringType)
sqlContext.read.schema(schema).json("/json/file/path").show
Also, look into this and this
You can create nested JSON Schema like below.
For example:
{
"field1": {
"field2": {
"field3": "create",
"field4": 1452121277
}
}
}
val schema = (new StructType)
.add("field1", (new StructType)
.add("field2", (new StructType)
.add("field3", StringType)
.add("field4", LongType)
)
)
Finally i found the problem.
The problem was on these lines:
val myStructType = new StructType()
myStructType.add("mySchemaStructType",mySchemaStructType)
i have to use this line:
val mySchemaStructType = DataType.fromJson(schema_json.head).asInstanceOf[StructType]
I have to cast StructType from DataType in order to get things working.

multipart/form-data using scala-dispatch

I am using scala-dispatch library as http client. I wanna post multipart/form-data with form values. Can anyone help me?
My Code:
val host_url : Req = url("http://localhost:8080/multipart-sample/profile/uploadfile").POST.setContentType("multipart/form-data", "UTF-8")
val request = host_url.addBodyPart(new FilePart("imagefile", new File("/path/to/file"))).addParameter("name", "sample_name").addParameter("age", "sample_age").addParameter("gender", "gender")
Http(request OK as.String ) onComplete {
case Success(s) => println(s)
case Failure(e) => e.printStackTrace
}
I get the following error. My server does not throw any error. So 500 is not from server.
java.util.concurrent.ExecutionException: dispatch.StatusCode: Unexpected response status: 500
at com.ning.http.client.providers.netty.future.NettyResponseFuture.abort(NettyResponseFuture.java:229)
at com.ning.http.client.providers.netty.request.NettyRequestSender.abort(NettyRequestSender.java:416)
at com.ning.http.client.providers.netty.handler.HttpProtocol.handle(HttpProtocol.java:492)
at com.ning.http.client.providers.netty.handler.Processor.messageReceived(Processor.java:89)
at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
at org.jboss.netty.handler.stream.ChunkedWriteHandler.handleUpstream(ChunkedWriteHandler.java:142)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
at org.jboss.netty.handler.codec.http.HttpContentDecoder.messageReceived(HttpContentDecoder.java:108)
at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:296)
at org.jboss.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:459)
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.callDecode(ReplayingDecoder.java:536)
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.messageReceived(ReplayingDecoder.java:485)
at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)
at org.jboss.netty.handler.codec.http.HttpClientCodec.handleUpstream(HttpClientCodec.java:92)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)
at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88)
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:108)
at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:337)
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:89)
at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)
at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: dispatch.StatusCode: Unexpected response status: 500
at dispatch.OkHandler$class.onStatusReceived(handlers.scala:37)
at dispatch.OkFunctionHandler.onStatusReceived(handlers.scala:29)
at com.ning.http.client.providers.netty.handler.HttpProtocol.exitAfterHandlingStatus(HttpProtocol.java:378)
at com.ning.http.client.providers.netty.handler.HttpProtocol.handleHttpResponse(HttpProtocol.java:429)
at com.ning.http.client.providers.netty.handler.HttpProtocol.handle(HttpProtocol.java:476)
... 31 more
Finally I found the answer for my question.
val request = host_url.addBodyPart(new FilePart("imagefile", new File("/path/to/file")))
.addParameter("name", "sample_name")
.addParameter("age", "sample_age")
.addParameter("gender", "gender")
replace this with the following
val request = host_url.addBodyPart(new FilePart("imagefile", new File("/path/to/file")))
.addBodyPart(new StringPart("param", "value"))

Standalone Spark Task Hangs When Inserting Into DB

I have a standalone spark 1.4.1 job that runs on a Red Hat box I submit via spark-submit that sometimes hangs during insertion of data from an RDD. I have auto-commit on the connection turned off and commit the transactions in batches of insertions. What the logs show me before it hangs:
16/03/25 14:00:05 INFO Executor: Finished task 3.0 in stage 138.0 (TID 915). 1847 bytes result sent to driver
16/03/25 14:00:05 DEBUG AkkaRpcEnv$$anonfun$actorRef$lzycompute$1$1$$anon$1: [actor] received message AkkaMessage(StatusUpdate(915,FINISHED,java.nio.HeapByteBuffer[pos=0 lim=1847 cap=1
16/03/25 14:00:05 DEBUG AkkaRpcEnv$$anonfun$actorRef$lzycompute$1$1$$anon$1: Received RPC message: AkkaMessage(StatusUpdate(915,FINISHED,java.nio.HeapByteBuffer[pos=0 lim=1847 cap=1847
16/03/25 14:00:05 DEBUG TaskSchedulerImpl: parentName: , name: TaskSet_138, runningTasks: 1
16/03/25 14:00:05 DEBUG AkkaRpcEnv$$anonfun$actorRef$lzycompute$1$1$$anon$1: [actor] handled message (0.118 ms) AkkaMessage(StatusUpdate(915,FINISHED,java.nio.HeapByteBuffer[pos=621 li
16/03/25 14:00:05 INFO TaskSetManager: Finished task 3.0 in stage 138.0 (TID 915) in 7407 ms on localhost (23/24)
16/03/25 14:00:05 TRACE DAGScheduler: Checking for newly runnable parent stages
16/03/25 14:00:05 TRACE DAGScheduler: running: Set(ResultStage 138)
16/03/25 14:00:05 TRACE DAGScheduler: waiting: Set()
16/03/25 14:00:05 TRACE DAGScheduler: failed: Set()
16/03/25 14:00:10 DEBUG AkkaRpcEnv$$anonfun$actorRef$lzycompute$1$1$$anon$1: [actor] received message AkkaMessage(Heartbeat(driver,[Lscala.Tuple2;#7ed52306,BlockManagerId(driver, local
16/03/25 14:00:10 DEBUG AkkaRpcEnv$$anonfun$actorRef$lzycompute$1$1$$anon$1: Received RPC message: AkkaMessage(Heartbeat(driver,[Lscala.Tuple2;#7ed52306,BlockManagerId(driver, localhos
16/03/25 14:00:10 DEBUG AkkaRpcEnv$$anonfun$actorRef$lzycompute$1$1$$anon$1: [actor] handled message (0.099 ms) AkkaMessage(Heartbeat(driver,[Lscala.Tuple2;#7ed52306,BlockManagerId(dri
And then it just repeats the last 3 lines with this intermittently:
16/03/25 14:01:04 TRACE HeartbeatReceiver: Checking for hosts with no recent heartbeats in HeartbeatReceiver.
The kicker is that I can't take a look at the web UI due to some firewall issues on these machines. What I noticed is that this issue was more prevalent when I was inserting with batches of 1000 than with 100. This is the scala code that looks to be the culprit.
//records should have up to INSERT_BATCH_SIZE entries
private def insertStuff(records: Seq[(String, (String, Stuff1, Stuff2, Stuff3))]) {
if (!records.isEmpty) {
//get statement used for insertion (instantiated in an array of statements)
val stmt = stuffInsertArray(//stuff)
logger.info("Starting insertions on stuff" + table + " for " + time + " with " + records.length + " records")
try {
records.foreach(record => {
//get vals from record
...
//perform sanity checks
if (//validate stuff)
{
//log stuff because it didn't validate
}
else
{
stmt.setInt(1, //stuff)
stmt.setLong(2, //stuff)
...
stmt.addBatch()
}
})
//check if connection is still valid
if (!connInsert.isValid(VALIDATE_CONNECTION_TIMEOUT))
{
logger.error("Insertion connection is not valid while inserting stuff.")
throw new RuntimeException(s"Insertion connection not valid while inserting stuff.")
}
logger.debug("Stuff insertion executing batch...")
stmt.executeBatch()
logger.debug("Stuff insertion execution complete. Committing...")
//commit insert batch. Either INSERT_BATCH_SIZE insertions planned or the last batch to be done
insertCommit() //this does the commit and resets some counters
logger.debug("stuff insertion commit complete.")
} catch {
case e: Exception => throw new RuntimeException(s"insertStuff exception ${e.getMessage}")
}
}
}
And here's how it gets called:
//stuffData is an RDD
stuffData.foreachPartition(recordIt => {
//new instance of the object of whose member function we're currently in
val obj = new Obj(clusterInfo)
recordIt.grouped(INSERT_BATCH_SIZE).foreach(records => obj.insertStuff(records))
})
All the extra logging and connection checking I put in just to isolate the issue but since I write for every batch of insertions, the logs get convoluted. If I serialize the insertions, the issue still persists. Any idea why the last task (out of 24) doesn't finish? Thanks.

ReactiveMongo 0.11.9 throws No primary node is available while connecting to mongodb 3.0.4

I simply have a reactivemongo (version : 0.11.9) insertion query as below,
class MongoInsertQuery extends Query {
val DbName = "events-db"
val CollectionName = "EventStream"
val driver = new MongoDriver
val connection = driver.connection(List("127.0.0.1:27018"))
def insert() = {
val db = connection(DbName)
val collection: BSONCollection = db(CollectionName)
val futureResult: Future[WriteResult] = collection.insert(BSONDocument("type" -> "Product_Received"))
futureResult onComplete {
case Success(s) => println("Success " + s)
case Failure(e) => {
println("error " + e.getMessage)
e.printStackTrace()
}
}
}
}
Not that important, but Scala Play REST controller would call that method
def sayBeard = Action { request =>
new MongoInsertQuery().insert()
Ok(Json.obj("message" -> "TODO respond writeResult"))
}
When I call the endpoint,
$ curl -XGET localhost:9000/sayBeard
{"message":"TODO respond writeResult"}
It inserts successfully to mongodb 2.4.14,
precise64(mongod-2.4.14) events-db> db.EventStream.find({})
{
"_id": ObjectId("5683337120906c127504eb79"),
"type": "Product_Received"
}
But I get readAndDeserialize error with Failure on future onComplete.
[info] - play.api.Play - Application started (Dev)
error 83
java.lang.ArrayIndexOutOfBoundsException: 83
at org.jboss.netty.buffer.LittleEndianHeapChannelBuffer.getInt(LittleEndianHeapChannelBuffer.java:69)
at reactivemongo.api.SerializationPack$class.readAndDeserialize(serializationpack.scala:31)
at reactivemongo.api.BSONSerializationPack$.readAndDeserialize(serializationpack.scala:41)
at reactivemongo.api.collections.GenericCollection$$anonfun$insert$1$$anonfun$apply$12.apply(genericcollection.scala:279)
at reactivemongo.api.collections.GenericCollection$$anonfun$insert$1$$anonfun$apply$12.apply(genericcollection.scala:279)
at scala.util.Success$$anonfun$map$1.apply(Try.scala:237)
at scala.util.Try$.apply(Try.scala:192)
at scala.util.Success.map(Try.scala:237)
at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:235)
at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:235)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)
at scala.concurrent.impl.ExecutionContextImpl$AdaptedForkJoinTask.exec(ExecutionContextImpl.scala:121)
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
My intention here is to read the WriteResult (N, message) on writeResult after inserting into Collection.
With mongo 3.0.6, It couldn't even find mongodb.
23:02:02.172 [ForkJoinPool-6-worker-9] ERROR reactivemongo.api.Failover2 - Got an error, no more attempts to do. Completing with a failure...
reactivemongo.core.actors.Exceptions$PrimaryUnavailableException$: MongoError['No primary node is available!']
at reactivemongo.core.actors.Exceptions$PrimaryUnavailableException$.<clinit>(actors.scala) ~[reactivemongo_2.11-0.11.9.jar:0.11.9]
at reactivemongo.core.actors.MongoDBSystem$$anonfun$reactivemongo$core$actors$MongoDBSystem$$pickChannel$4.apply(actors.scala:681) ~[reactivemongo_2.11-0.11.9.jar:0.11.9]
at reactivemongo.core.actors.MongoDBSystem$$anonfun$reactivemongo$core$actors$MongoDBSystem$$pickChannel$4.apply(actors.scala:681) ~[reactivemongo_2.11-0.11.9.jar:0.11.9]
at scala.Option.getOrElse(Option.scala:121) ~[scala-library-2.11.7.jar:?]
at reactivemongo.core.actors.MongoDBSystem$class.reactivemongo$core$actors$MongoDBSystem$$pickChannel(actors.scala:681) ~[reactivemongo_2.11-0.11.9.jar:0.11.9]
at reactivemongo.core.actors.MongoDBSystem$$anonfun$4.applyOrElse(actors.scala:335) ~[reactivemongo_2.11-0.11.9.jar:0.11.9]
at scala.PartialFunction$OrElse.applyOrElse(PartialFunction.scala:170) ~[scala-library-2.11.7.jar:?]
at akka.actor.Actor$class.aroundReceive(Actor.scala:467) ~[akka-actor_2.11-2.3.13.jar:?]
at reactivemongo.core.actors.LegacyDBSystem.aroundReceive(actors.scala:796) ~[reactivemongo_2.11-0.11.9.jar:0.11.9]
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:516) ~[akka-actor_2.11-2.3.13.jar:?]
at akka.actor.ActorCell.invoke(ActorCell.scala:487) ~[akka-actor_2.11-2.3.13.jar:?]
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:238) ~[akka-actor_2.11-2.3.13.jar:?]
at akka.dispatch.Mailbox.run(Mailbox.scala:220) ~[akka-actor_2.11-2.3.13.jar:?]
at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:397) ~[akka-actor_2.11-2.3.13.jar:?]
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) [scala-library-2.11.7.jar:?]
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) [scala-library-2.11.7.jar:?]
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) [scala-library-2.11.7.jar:?]
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) [scala-library-2.11.7.jar:?]
Though, I see connection log on mongo,
2015-12-30T23:21:57.688-0500 I NETWORK [initandlisten] connection accepted from 127.0.0.1:51663 #11 (11 connections now open)
Reference
http://reactivemongo.org/releases/0.11/documentation/tutorial/write-documents.html
https://groups.google.com/forum/#!topic/reactivemongo/0jxS1cgXjP8
So, the thing is reactivemongo 0.11.4 supports mongodb 3.0+. And then I had to update the mongodb host.
val driver = new MongoDriver
val connection = driver.connection(List("127.0.0.1:27017"))
Read
java.lang.ArrayIndexOutOfBoundsException on update with mongo 2.4.12 #394

java.lang.Process hang when recursively called

My program recursivly calls the McAfee OnDemad Virusscanner for a specific path. In a loop I fill the path with several files, scan it, remove the files, fill it and so on.
After a while the program suddenly hangs and I've no clue for the reason.
Calendar cl = Calendar.getInstance();
String cmd="uvscan -v /var/tmp/McAfee/scanFiles/"
try {
long start=cl.getTimeInMillis();
process = Runtime.getRuntime().exec(cmd, null);
Worker worker = new Worker(process);
worker.start();
try {
LOGGER.debug("Virusscan timeout set to {}ms", timeout);
worker.join(timeout);
if (worker.exit != null)
workerRC=worker.exit;
else {
cl = Calendar.getInstance();
long waitTime=cl.getTimeInMillis()-start;
throw new TimeoutException("Virusscan timeout after " + waitTime + "ms");
}
// else
// throw new TimeoutException();
} catch(InterruptedException ex) {
worker.interrupt();
Thread.currentThread().interrupt();
cl = Calendar.getInstance();
long waitTime=cl.getTimeInMillis()-start;
throw new TimeoutException("Virusscan timeout after " + waitTime + "ms");
}
File scanLog = new File(ConfigReader.getScanLog());
if (!ConfigReader.mustKeepScanLog()) scanLog.deleteOnExit();
LOGGER.debug("ScanLog is: " + scanLog.getPath() + " - RC=" + workerRC);
BufferedWriter bw = new BufferedWriter(new FileWriter(scanLog));
BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
// read the output from the command
while ((buffer = stdInput.readLine()) != null) {
inspectScanlog(buffer, workerRC);
bw.write(buffer+"\n");
LOGGER.debug("Scan STDOUT: " + buffer);
}
BufferedReader stdErr = new BufferedReader(new InputStreamReader(process.getErrorStream()));
while ((buffer = stdErr.readLine()) != null) {
LOGGER.debug("Scan STDERR: " + buffer);
}
bw.close();
cl = Calendar.getInstance();
long waitTime=cl.getTimeInMillis()-start;
LOGGER.info("Virusscan took " + waitTime + "ms");
if (workerRC != 0){
int cc=12;
ConfigReader.setMaxCC(cc);
LOGGER.error("RC={} - Virusscan ended with error. CMD=",cc, cmd);
if (workerRC==13) {
LOGGER.error("RC={} - The scanner found one or more viruses or hostile objects - such as a Trojan-horse program, joke program, or test file.", cc);
}
}
}
catch (Exception e) {
int cc=12;
ConfigReader.setMaxCC(cc);
LOGGER.error("RC={} - {}",cc, e.getMessage());
e.printStackTrace();
} finally {
if (process!=null) {
process.destroy();
}
}
It looks like a hang of the complete program; even the timeout (240000ms) doesn't match. The GC-log seems kind of interrupted:
258.070: [Full GC [PSYoungGen: 13456K->7362K(85120K)] [PSOldGen: 59271K->60735K(81728K)] 72727K->68098K(166848K) [PSPermGen: 16282K->16282K(30400K)], 0.3019290 secs] [Times: user=0.31 sys=0.00, real=0.31 secs]
264.208: [GC [PSYoungGen: 65466K->8773K(92224K)] 126202K->69581K(173952K), 0.0528360 secs] [Times: user=0.10 sys=0.00, real=0.05 secs]
265.445: [GC [PSYoungGen: 81774K->9133K(92096K)] 142582K->70061K(173824K), 0.0205430 secs] [Times: user=0.03 sys=0.00, real=0.02 secs]
266.916: [GC [PSYoungGen: 82515K->9698K(100096K)] 143443K->70658K(181824K), 0.0189050 secs] [Times: user=0.04 sys=0.00, real=0.02 secs]
267.817: [GC [PSYoungGen: 92311K->1436K(100480K)] 153271K->70986K(182208K), 0.0210400 secs] [Times: user=0.03 sys=0.01, real=0.02 secs]
274.208: [GC [PSYoungGen: 84072K->672K(112256K)] 153622K->71297K(193984K), 0.0029610 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
275.769: [GC [PSYoungGen: 94880K->500K(112832K)] 165505K->71732K(194560K), 0.0022440 secs]
The uvscan-command has been called 277.609 seconds after program-start.
Could anyone suggest how to get the reason for the hang?
Thanks in advance,
Ulrich