socketRead0(Native Method) indefinitely blocked

Product/components used and version/fix level:

<c8y.version>1011.0.17</c8y.version>

Detailed explanation of the problem:

Hi it’s Luca from DAC.
We use a Java agent to send events to the platform. However, sometimes when we try to retrieve the internal ID of a device, the thread gets stuck indefinitely.

This is the jstack dump:

Thread-12" #23 prio=5 os_prio=0 tid=0x6ac0f000 nid=0xb35 runnable [0x6a91e000]
   java.lang.Thread.State: RUNNABLE
	at java.net.SocketInputStream.socketRead0(Native Method)
	at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
	at java.net.SocketInputStream.read(SocketInputStream.java:171)
	at java.net.SocketInputStream.read(SocketInputStream.java:141)
	at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
	at sun.security.ssl.InputRecord.readV3Record(InputRecord.java:593)
	at sun.security.ssl.InputRecord.read(InputRecord.java:532)
	at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:983)
	- locked <0x702dcf70> (a java.lang.Object)
	at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1385)
	- locked <0x702dd020> (a java.lang.Object)
	at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1413)
	at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1397)
	at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:436)
	at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:384)
	at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
	at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:374)
	at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393)
	at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
	at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)
	at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
	at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
	at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
	at org.glassfish.jersey.apache.connector.ApacheConnector.apply(ApacheConnector.java:483)
	at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:297)
	at org.glassfish.jersey.client.JerseyInvocation.lambda$invoke$0(JerseyInvocation.java:630)
	at org.glassfish.jersey.client.JerseyInvocation$$Lambda$116/368733.call(Unknown Source)
	at org.glassfish.jersey.client.JerseyInvocation.call(JerseyInvocation.java:665)
	at org.glassfish.jersey.client.JerseyInvocation.lambda$runInScope$3(JerseyInvocation.java:659)
	at org.glassfish.jersey.client.JerseyInvocation$$Lambda$117/15699221.call(Unknown Source)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:205)
	at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:390)
	at org.glassfish.jersey.client.JerseyInvocation.runInScope(JerseyInvocation.java:659)
	at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:629)
	at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:408)
	at org.glassfish.jersey.client.JerseyInvocation$Builder.get(JerseyInvocation.java:308)
	at com.cumulocity.sdk.client.RestConnector.getClientResponse(RestConnector.java:136)
	at com.cumulocity.sdk.client.RestConnector.get(RestConnector.java:109)
	at com.cumulocity.sdk.client.identity.IdentityApiImpl.getExternalId(IdentityApiImpl.java:72)
	at c8y.mqtt.EventsBuilder.tryGetBinding(EventsBuilder.java:76)
	at c8y.mqtt.EventsBuilder.sendEventToC8yViaRest(EventsBuilder.java:31)
	at c8y.mqtt.LocalQueueConsumer.consumeLocalQueueMessages(LocalQueueConsumer.java:62)
	at c8y.mqtt.LocalQueueConsumer.run(LocalQueueConsumer.java:36)
	at java.lang.Thread.run(Thread.java:748)

any idea?

Error messages / full error message screenshot / log file:

Question related to a free trial, or to a production (customer) instance?

Customer

This is pretty old and shouldn’t used anymore.
Hard to say because it could be anything, mainly related to the sdk version I guess. Maybe missing exception handling? SDKException is thrown when an deviceID could not retrieved.

This is the incriminated method:

	static GId tryGetBinding(ID extId, Platform platform) {
		ExternalIDRepresentation eir = null;
		try {
			eir = platform.getIdentityApi().getExternalId(extId);
		} catch (SDKException x) {
			if (x.getHttpStatus() != 404) {
				throw x;
			}
		}
		return eir != null ? eir.getManagedObject().getId() : null;
	}

The point I think is that we don’t get a response and we never delete devices so something has to be found.