My websocket(using test url) is automatically calling onCloseCallBack, the logs says "SocketException:Connection reset"

Hi, I am using this Java lib GitHub - binance/binance-connector-java .

In the test env using test websocket url, it sometimes call onCloseCallBack and throws the provided exception. Does anyone know why? maybe because it is test url and not prod url ?

31-08-2022 17:07:02.087 261952625 [OkHttp https://testnet.binance.vision/…] ERROR c.b.c.c.utils.WebSocketConnection - [Connection 11] Failure
java.net.SocketException: Connection reset
at java.base/java.net.SocketInputStream.read(SocketInputStream.java:186)
at java.base/java.net.SocketInputStream.read(SocketInputStream.java:140)
at java.base/sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRecord.java:478)
at java.base/sun.security.ssl.SSLSocketInputRecord.readHeader(SSLSocketInputRecord.java:472)
at java.base/sun.security.ssl.SSLSocketInputRecord.bytesInCompletePacket(SSLSocketInputRecord.java:70)
at java.base/sun.security.ssl.SSLSocketImpl.readApplicationRecord(SSLSocketImpl.java:1454)
at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.read(SSLSocketImpl.java:1065)
at okio.InputStreamSource.read(JvmOkio.kt:90)
at okio.AsyncTimeout$source$1.read(AsyncTimeout.kt:129)
at okio.RealBufferedSource.request(RealBufferedSource.kt:206)
at okio.RealBufferedSource.require(RealBufferedSource.kt:199)
at okio.RealBufferedSource.readByte(RealBufferedSource.kt:209)
at okhttp3.internal.ws.WebSocketReader.readHeader(WebSocketReader.kt:119)
at okhttp3.internal.ws.WebSocketReader.processNextFrame(WebSocketReader.kt:102)
at okhttp3.internal.ws.RealWebSocket.loopReader(RealWebSocket.kt:293)
at okhttp3.internal.ws.RealWebSocket$connect$1.onResponse(RealWebSocket.kt:195)
at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)

The testnet websocket server base url is wss://testnet.binance.vision/

Can you please provide the full url used to connect to the websocket?

I am using 2 streams. 1 for streaming market prices and 1 for listenUserStream(events from my wallet,like when a trade is set or fulfilled…). The error I get is for the listenUserStream and that stream is using TESTNET_WSS_URL = “wss://testnet.binance.vision”

but when I stream market prices I use wss://stream.binance.com:9443 . I have not got error on this stream, seems to work fine. I only get error for the listenUserStream so it might have to do with the testnet url.

In the second part of the error logs(after the first section of logs I wrote above ) it says →
Connecting to wss://testnet.binance.vision/wql… why this url?

31-08-2022 16:48:46.410 260856948 [OkHttp https://testnet.binance.vision/…] ERROR c.j.binanceapi.binance.BinanceApi - onFailureCallback()
31-08-2022 16:48:46.410 260856948 [OkHttp https://testnet.binance.vision/…] INFO c.b.c.c.utils.WebSocketConnection - [Connection 15] Connecting to testnet.binance.vision/ws/wqlVEJMRj2vqTMJlAAljHNtJJMD9VAvhxFLGp7ScfOanamS3Uff23o88D4IS

I suggest opening a ticket on the github repository with a code snippet for the team to better diagnose the issue.

1 Like

Hi , they have now created a PR for this issue. refactor(websockets)!: remove WebSocketCallback abstraction to avoid … by Hazard4U · Pull Request #51 · binance/binance-connector-java · GitHub

Now we can get more catch the error message in onFailureCallback, and see why its failing. Good improvement