linux - Java 2 minute delay sometimes when connecting socket? -


i'm baffled following mystery. when testing application, (maybe 25% of time) 2 minute delay when connecting ssl socket. i'm using java 8, ubuntu 16.04. when use wireshark can see nothing sent on network target server. maybe there other network traffic dns resolving. delay 2 minutes uncertainty of no more couple seconds. last log message before hangs is:

debug org.apache.http.conn.ssl.sslconnectionsocketfactory - connecting socket redacted:443 timeout 0 

pausing in debugger verifies it's blocked in socket connect code in class plainsocketimpl:

native void socketconnect(inetaddress address, int port, int timeout) 

i'm pretty sure i'd have noticed if hang happens other applications, think affects java program. (kotlin) code follows:

import org.apache.http.client.methods.httppost import org.apache.http.config.registrybuilder import org.apache.http.conn.socket.connectionsocketfactory import org.apache.http.conn.ssl.sslconnectionsocketfactory import org.apache.http.entity.stringentity import org.apache.http.impl.client.closeablehttpclient import org.apache.http.impl.client.httpclients import org.apache.http.impl.conn.poolinghttpclientconnectionmanager import org.apache.http.util.entityutils import java.security.securerandom import javax.net.ssl.*  fun main(args: array<string>) {   val client = sslclient()    val auth = authrequest()   val ares = auth.post(client)   val token = ares.value   println(token) }  class sslclient {     val client : closeablehttpclient      init {         val config = config         config.loadcerts()         val ctx = sslcontext.getinstance("tlsv1.2")         val kmf = keymanagerfactory.getinstance(keymanagerfactory.getdefaultalgorithm())         kmf.init(config.clientsslcerts, config.keypassword.tochararray())         val tmf = trustmanagerfactory.getinstance(trustmanagerfactory.getdefaultalgorithm())         tmf.init(config.serversslcerts)         ctx.init(kmf.keymanagers, tmf.trustmanagers, securerandom())         val sslsf = sslconnectionsocketfactory(ctx)          val r = registrybuilder.create<connectionsocketfactory>()                 .register("https", sslsf)                 .build()         val cm = poolinghttpclientconnectionmanager(r)         client = httpclients.custom()                 .setconnectionmanager(cm)                 .build()     }      fun post(endpoint : string) : httppost {         val post = httppost(endpoint)         post.addheader("content-type", "application/xml")         return post     }      fun execute(post : httppost, xmlbody : string) : string {         println(xmlbody)         post.entity = stringentity(xmlbody, charsets.utf_8)         client.execute(post).use { response ->             response.allheaders.foreach { println(it.tostring()) }             println(response.statusline.tostring())             if (response.statusline.statuscode !in 200..299) {                 throw exception(response.statusline.tostring())             }             val entity = response.entity             if (entity == null || entity.contentlength == 0l) {                 throw exception("no body content in http response")             }             val result = entityutils.tostring(entity)             println(result)             return result         }     } } 

the last clue have offer time spent paused in debugger doesn't count towards 2 minutes. can wait 5 minutes paused, unpause , still take 2 minutes. tells me it's not waiting external process complete because external process make progress during paused time.


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -