-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crash immediately after State Preservation/Restoration - "Connected peripheral is assigned a nil value despite Bluejay has successfully finished a connection." #206
Comments
I'm seeing a lot of this crash with my users, and so I tried to gather some more information. I was able to reproduce this crash several times at my desk. The process was:
Sometimes (not always), when the state preservation/restoration occurred, I would get the following sequence of events. It seems like it's restoring the system back to a state where it's trying to connect to the peripheral, but then it gets a disconnect. Getting the disconnect is weird because the peripheral was powered off when I started the app. Perhaps the disconnect is queued within iOS, and is then handled by the app once it starts up again? Based on the Bluejay logs, I would have expected that when I powered the peripheral on, iOS would not automatically reconnect, since the logs indicated auto-reconnect was false. However, when I power the peripheral on, iOS automatically reconnects to it, and Bluejay crashes. I think Bluejay is crashing because as part of the disconnect sequence,
|
Another thing I noticed is that I see the following log entries repeated, which is surprising. [Bluejay] [main] > Did fail to to restore connection with error: Unexpected disconnect I also get 2 calls to: In looking at code, maybe this is happening because the initial connect request fails, which causes restoration to "complete", and then there's also a disconnect happening, which also causes the restoration to "complete"? |
Hi @SaintNicholas state restoration is one of the hardest things to get right, and obviously Bluejay is not quite there yet. I remember reviewing another similar bug report internally here at Steamclock, but can't remember what became of it - maybe because I do remember something along the lines of iOS 12 may have different state restoration behaviours, or possibly only different in some unknown cases, or in some iOS devices, or on certain iOS versions, or perhaps even dependent on the Bluetooth LE peripheral itself! We are very busy right now, so I don't have the bandwidth to provide an official fix to you in a timely manner, but I do have some ideas for a solution that you could try in your fork. If you look at line 1308 in
Based on your specific report and logs, there may be multiple issues, but one of the most alarming one is: we're getting a rogue "did connect" callback from CB that doesn't seem to come from any Bluejay connection, nor a CB state restoration? Does this conclusion sound right to you as well? To me, state restoration actually seems to be working fine based on your logs, regardless of whether the restoration reconnected or disconnected, it still completed all the way. But we just need to zero in on what is triggering that final extra and rogue "did connect" event after everything seems to be finished already. If you can repro this, try breakpointing on line 1308 and examine all the peripheral references:
And also see if you can inspect the state of the Bluejay queue and other related states. They may tell us more about where this "did connect" is coming from. If we can figure that out, then we may be able to handle it. |
Hi @jeremychiang I was able to reproduce it again, and collect some more information. It's at the bottom of the response. I agree that the rogue 'did connect' callback is unexpected. I think the information I collected shows that Bluejay isn't expecting the connection, as all the variables you asked me to look at are nil, and the queue is empty. Is it possible that when bluejay says 'Should auto-reconnect: false' that it's wrong, iOS is going to be auto-reconnecting? In my experience with other disconnects, when Bluejay says 'The disconnect is unexpected.', it usually does auto-reconnect, and I'm not sure why this case is different. Also, do you have any idea why I'm seeing multiple calls to
|
Hey @jeremychiang, I'm seeing another crash that's very similar to what I discussed above, but different. This crash is from restoring a 'connected' peripheral, where the discussion above is describing a crash from restoring a 'connecting' peripheral.
|
Thank you for your report. This is on my radar, but we do have a few other features and fixes planned. We'll circle back to this as soon as we can. |
Any change this could be revisited? We are seeing this a lot with our users. We can at least help to test the possible fix. |
Summary:
I stumbled upon a crash in my app that happens immediately on app startup, after state preservation/restoration has completed.
Steps to Reproduce:
Actual Result:
I get a crash in
public func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
at line
precondition(connectedPeripheral != nil, "Connected peripheral is assigned a nil value despite Bluejay has successfully finished a connection.")
The log contains:
I do see that I am doing a characteristic read in the middle of this process, but it's not a critical read, and I had thought that it would be ok if that just failed (assuming bluejay handled it ok).
Expected Result:
It doesn't crash I guess?
Device, Build, OS:
iPhone Xs, iOS 12.3, bluejay v0.8.5
The text was updated successfully, but these errors were encountered: