Skip to content

[Bug]: Realtime socket never reconnects due to deadlock #504

@jmacindoe

Description

@jmacindoe

General Info

  • I checked for similar bug report
  • I am using the latest version
  • I checked the troubleshooting page for similar problems
  • I enabled logging and checked the logs

Version(s)

2.1.5+

Target(s)

Test on Android

What happened? (include your code)

Starting in 2.1.5, the realtime socket fails to retry connecting after a disconnect. I believe this is caused by a deadlock with the mutex added in #483. When an error occurs RealtimeImpl.connect() invokes itself recursively (here) but it does not release the mutex here and so the recursive call suspends forever.

Steps To Reproduce (optional)

  1. Connect using Realtime
  2. Turn off your internet connection
  3. Only one attempt to reconnect is made and then Realtime stops responding. Calls to Realtime.connect() suspend forever.

Relevant log output (optional)

2024-03-07 13:26:11.282 29152-29725 Realtime                com.example                     E  Error while listening for messages. Trying again in 7s
                                                                                                    java.net.SocketException: Software caused connection abort
                                                                                                    	at java.net.SocketInputStream.socketRead0(Native Method)
                                                                                                    	at java.net.SocketInputStream.socketRead(SocketInputStream.java:118)
                                                                                                    	at java.net.SocketInputStream.read(SocketInputStream.java:173)
                                                                                                    	at java.net.SocketInputStream.read(SocketInputStream.java:143)
                                                                                                    	at com.android.org.conscrypt.ConscryptEngineSocket$SSLInputStream.readFromSocket(ConscryptEngineSocket.java:945)
                                                                                                    	at com.android.org.conscrypt.ConscryptEngineSocket$SSLInputStream.processDataFromSocket(ConscryptEngineSocket.java:909)
                                                                                                    	at com.android.org.conscrypt.ConscryptEngineSocket$SSLInputStream.readUntilDataAvailable(ConscryptEngineSocket.java:824)
                                                                                                    	at com.android.org.conscrypt.ConscryptEngineSocket$SSLInputStream.read(ConscryptEngineSocket.java:797)
                                                                                                    	at okio.InputStreamSource.read(JvmOkio.kt:93)
                                                                                                    	at okio.AsyncTimeout$source$1.read(AsyncTimeout.kt:153)
                                                                                                    	at okio.RealBufferedSource.request(RealBufferedSource.kt:209)
                                                                                                    	at okio.RealBufferedSource.require(RealBufferedSource.kt:202)
                                                                                                    	at okio.RealBufferedSource.readByte(RealBufferedSource.kt:212)
                                                                                                    	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.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
                                                                                                    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
                                                                                                    	at java.lang.Thread.run(Thread.java:1012)
2024-03-07 13:26:11.283 29152-29724 Realtime                com.example                     D  Closing websocket connection
2024-03-07 13:26:18.286 29152-29746 Realtime                com.example                     D  Reconnecting...
2024-03-07 13:26:18.365 29152-29523 Realtime                com.example                     E  Error while trying to connect to realtime websocket. Trying again in 7s
                                                                                                    URL: wss://exampleurl.supabase.co/realtime/v1/websocket?apikey=someKey&vsn=1.0.0
2024-03-07 13:26:18.366 29152-29523 Realtime                com.example                     D  Closing websocket connection

No further logs from Realtime occur and there are no further attempts to reconnect.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions