Skip to main content
intersoldi
Bronze ⭐️⭐️⭐️
June 11, 2026
Question

Sparklyr job hang

We are running a sparkly job that runs queries on cloudera CDP hive cluster. The job sometimes stops before a dbwriteTable function, doing nothing and running indefinitely. The job doesn't always stop in the same point, but always during this trywrite function invocation, not catching any error:

trywrite = function(sc, new_name, df, log_obj, wait_sec = 600, max_wait = 3600)
{
start_time = Sys.time()
while (difftime(Sys.time(), start_time, units = 'secs') <= max_wait) {
print(paste0('Attempt to write table: ', new_name, ' - ', Sys.time()))
# Connection is valid?
if (!DBI::dbIsValid(sc)) {
error(log_obj, paste0('Connection not valid during write table: ', new_name))
stop(paste0('Failed to write table: ', new_name))
}
tryCatch({
print(paste0('Writing table: ', new_name))
result = DBI::dbWriteTable(sc, new_name, df)
print(paste0('Write completed table: ', new_name, ' - ', Sys.time()))
return(result)
}, error = function(e) {
error(log_obj, paste0('Connection not valid during write table: ', new_name, ' - ', Sys.time()))
print(paste0('Error message: ', e$message))
print(paste0('Retrying in', wait_sec, ' seconds: ', Sys.time()))
Sys.sleep(wait_sec)
})
}
stop(paste0('Failed to write table before max time: ', new_name))
}    

 

4 replies

DianaTorres
Community Manager
Community Manager
June 13, 2026

@intersoldi Welcome to the Cloudera Community!

To help you get the best possible solution, I have tagged our Spark experts @vafs @Bharati @jagadeesan  who may be able to assist you further.

Please keep us updated on your post, and we hope you find a satisfactory solution to your query.

Translate
Regards, Diana Torres, Senior Community Moderator
vafs
Gold ⭐️⭐️⭐️
Gold ⭐️⭐️⭐️
June 15, 2026

Hello @intersoldi, 

Thanks for being part of our community. 

This could be an issue related to some threads blocked. 
Do you see anything on the YARN application log? 

On the Spark Event Log, does it always hang on the same task? 

Another thing you can try is to get jstacks and review them to see if they are hanging on any specific point or step, for example, a connection or thread. 

Translate
Regards, Andrés Fallas -- Was your question answered? Please take some time to click on "Accept as Solution" below this post. If you find a reply useful, say thanks by clicking on the thumbs-up button.
DianaTorres
Community Manager
Community Manager
June 22, 2026

@intersoldi Has the reply helped resolve your issue? If so, please mark the appropriate reply as the solution, as it will make it easier for others to find the answer in the future. Thanks.

Translate
Regards, Diana Torres, Senior Community Moderator
adunikama
Silver ⭐️
June 25, 2026

Spark lazily evaluates the workload. The actual execution happens when you write the output, usually. If it gets stuck there that means the workload is not tuned with respect to your infrastructure. Try checking the logs, most likely you need to tune your shuffle partition and/or repartition your data.🙂

Translate