supabase-community / realtime-swift

A Swift client for Supabase Realtime server.
MIT License
50 stars 13 forks source link

SIGABRT CRASH on HeartbeatTimer: malloc: Heap corruption detected, free list is damaged #17

Open MilesV64 opened 1 year ago

MilesV64 commented 1 year ago

Bug report

Describe the bug

While leaving my app open on a screen that has a channel subscription, after around 20 minutes without touching the app it crashed, saying "malloc: Heap corruption detected, free list is damaged". This has happened several times, on different devices.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Make a channel subscription:
let client = self.supabaseClient.realtime
client.connect()

let allChanges = client.channel(.column("id", value: id, table: "table-name", schema: "schema-name"))

client.onOpen { [weak self] in
   print("Realtime client opened")
}

allChanges.on(.update) { [weak self] _ in
    print("Realtime update")
}

allChanges.subscribe()

self.realtimeChannel = allChanges
  1. Wait with the app open for a while, while triggering lots of updates to the database on another device/directly to the db
  2. At a seemingly random time, the app will crash with a signal SIGABRT.

Expected behavior

The client should be able to stay open indefinitely with no crashes.

Screenshots

Image of where the crash occurred in the library Image of the thread stack trace

System information

Additional context

This is happening quite consistently, please advise how to fix the crash if it's a usage issue!

MilesV64 commented 1 year ago

@grsouza hey just tagging you cause I've seen you active in the community! This is a pretty gnarly issue for my app which I'm hoping to push to production very soon, do you have any idea of how much time you and others in the community have to spend on this? Happy to help however I can.

MilesV64 commented 1 year ago

My hunch is it's to do with the HeartbeatTimer having its own dispatch queue for the timer but then also all the Realtime code being executed in the delegate methods of URLSession, which could be a variety of different background threads