{"action":"created","issue":{"url":"https://api.github.com/repos/nats-io/java-nats/issues/130","repository_url":"https://api.github.com/repos/nats-io/java-nats","labels_url":"https://api.github.com/repos/nats-io/java-nats/issues/130/labels{/name}","comments_url":"https://api.github.com/repos/nats-io/java-nats/issues/130/comments","events_url":"https://api.github.com/repos/nats-io/java-nats/issues/130/events","html_url":"https://github.com/nats-io/java-nats/issues/130","id":257433468,"number":130,"title":"Support a socket read timeout in the connection properties","user":{"login":"mpilone","id":3026098,"avatar_url":"https://avatars2.githubusercontent.com/u/3026098?v=4","gravatar_id":"","url":"https://api.github.com/users/mpilone","html_url":"https://github.com/mpilone","followers_url":"https://api.github.com/users/mpilone/followers","following_url":"https://api.github.com/users/mpilone/following{/other_user}","gists_url":"https://api.github.com/users/mpilone/gists{/gist_id}","starred_url":"https://api.github.com/users/mpilone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpilone/subscriptions","organizations_url":"https://api.github.com/users/mpilone/orgs","repos_url":"https://api.github.com/users/mpilone/repos","events_url":"https://api.github.com/users/mpilone/events{/privacy}","received_events_url":"https://api.github.com/users/mpilone/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-09-13T15:56:17Z","updated_at":"2017-09-13T21:15:03Z","closed_at":null,"author_association":"NONE","body":"I ran into an issue where one of the machines running a nats instance locked up in a state where it would accept TCP connections but not respond/process data. That's a separate issue unrelated to nats. However while the machine was in this state, I found that Java applications using the Java client would hang at startup if they selected this broken remote server.\r\n\r\nFrom the stack trace (see below), it looks like the Java nats client is stuck on a read call that never returns. Looking through the code, it appears that a timeout used used during the socket connect call in TcpConnection around line 73, but no setSoTimeout is called on the socket after connection. My understanding is that the default read timeout of a Java socket is 0 which means it will block indefinitely.\r\n\r\nThere is a comment in TcpConnection around line 91 that seems to hit at someone thinking about adding a send/read timeout but it clearly isn't implemented:\r\n\r\n```void setConnectTimeout(int value) {\r\n        this.timeout = value;\r\n    }\r\n\r\n    // setSendTimeout?\r\n\r\n    boolean isSetup() {\r\n        return (client != null);\r\n    }\r\n```\r\n\r\nTo support the most robust fail over and startup, it seems like a socket read timeout needs to be set with either a reasonable default or configurable via options.\r\n\r\n-mike\r\n\r\nStack trace:\r\n```\"WrapperSimpleAppMain\" #16 prio=5 os_prio=0 tid=0x00007f8d04001000 nid=0x6191 runnable [0x00007f8d520e8000]\r\n   java.lang.Thread.State: RUNNABLE\r\n      at java.net.SocketInputStream.socketRead0(Native Method)\r\n      at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)\r\n      at java.net.SocketInputStream.read(SocketInputStream.java:170)\r\n      at java.net.SocketInputStream.read(SocketInputStream.java:141)\r\n      at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)\r\n      at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)\r\n      at java.io.BufferedInputStream.read(BufferedInputStream.java:345)\r\n      - locked <0x00000000f8d77a70> (a java.io.BufferedInputStream)\r\n      at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)\r\n      at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)\r\n      at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)\r\n      - locked <0x00000000f8d88588> (a java.io.InputStreamReader)\r\n      at java.io.InputStreamReader.read(InputStreamReader.java:184)\r\n      at java.io.BufferedReader.fill(BufferedReader.java:161)\r\n      at java.io.BufferedReader.readLine(BufferedReader.java:324)\r\n      - locked <0x00000000f8d88588> (a java.io.InputStreamReader)\r\n      at java.io.BufferedReader.readLine(BufferedReader.java:389)\r\n      at io.nats.client.ConnectionImpl.readLine(ConnectionImpl.java:1192)\r\n      at io.nats.client.ConnectionImpl.readOp(ConnectionImpl.java:1256)\r\n      at io.nats.client.ConnectionImpl.processExpectedInfo(ConnectionImpl.java:708)\r\n      at io.nats.client.ConnectionImpl.processConnectInit(ConnectionImpl.java:665)\r\n      at io.nats.client.ConnectionImpl.connect(ConnectionImpl.java:410)\r\n      at io.nats.client.ConnectionFactory.createConnection(ConnectionFactory.java:217)\r\n      at org.p.c.integration.util.camel.nats.NatsEndpoint.createConnection(NatsEndpoint.java:107)\r\n      at org.p.c.integration.util.camel.nats.NatsEndpoint.doStart(NatsEndpoint.java:61)```"},"comment":{"url":"https://api.github.com/repos/nats-io/java-nats/issues/comments/329299114","html_url":"https://github.com/nats-io/java-nats/issues/130#issuecomment-329299114","issue_url":"https://api.github.com/repos/nats-io/java-nats/issues/130","id":329299114,"user":{"login":"ColinSullivan1","id":11180189,"avatar_url":"https://avatars1.githubusercontent.com/u/11180189?v=4","gravatar_id":"","url":"https://api.github.com/users/ColinSullivan1","html_url":"https://github.com/ColinSullivan1","followers_url":"https://api.github.com/users/ColinSullivan1/followers","following_url":"https://api.github.com/users/ColinSullivan1/following{/other_user}","gists_url":"https://api.github.com/users/ColinSullivan1/gists{/gist_id}","starred_url":"https://api.github.com/users/ColinSullivan1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ColinSullivan1/subscriptions","organizations_url":"https://api.github.com/users/ColinSullivan1/orgs","repos_url":"https://api.github.com/users/ColinSullivan1/repos","events_url":"https://api.github.com/users/ColinSullivan1/events{/privacy}","received_events_url":"https://api.github.com/users/ColinSullivan1/received_events","type":"User","site_admin":false},"created_at":"2017-09-13T21:15:03Z","updated_at":"2017-09-13T21:15:03Z","author_association":"MEMBER","body":"@mpilone , thank you for raising the issue; this feature does look like it was considered at one time, and certainly seems like a reasonable request.  Would you be interested in submitting a PR?\r\n\r\nThanks,\r\nColin"}}
{"actor":{"display_login":"ColinSullivan1"}}