HKWorkoutSession cannot be stopped: Workout session is not current

We've been struggling with this error for a long time - periodically we receive the following message when trying to stop an HKWorkoutSession: "Workout session not current". I posted previously in the WatchOS 2 beta forum, but that thread is now read-only (https://forums.developer.apple.com/message/68844#68844). No HKWorkoutSessionDelegate methods are called prior to this, so to our users, it just appears that our app has broken.


Is anyone else experiencing this? The problem seems (sometimes at least) to coincide with the Apple HealthKit process crashing (com.apple.HealthKit) - I can reproduce the error reliably on the simulator by killing the "healthd" process using the MacOS Activity Monitor.


Please reply if you are also seeing this, especially if you have a workaround or any additional information that could help resolve it.

Has anyone found the solution to this? If I find it I'll post here.

Are you still seeing this with WatchOS 3.0? We haven't seen this problem since 3.0, although it has introduced other issues that were not present in 2.2.

I have been seeing this error with WatchOS 3.0. I will investigate further and note any important details and post here when done within the next couple weeks.

Same here, any solution?

I've been seeing this in WatchOS 4 in my app. Not sure what triggers it?


EDIT: in testing it seems that this is called when a workout spans 2 calendar days:


My Apple Watch app calls

.start
on a
HealthStore
object that begins a
WorkoutSession
. I find that if users begin a workout e.g. at 11:30pm on day 1 and end the workout at 12:30am on day 2, they are unable to
.end
the workout and the delegate method
func workoutSession(_ workoutSession: HKWorkoutSession, didFailWithError error: Error)
is called with an error message that the workout is not current.

Am I doing anything wrong or is this a bug? (I filed a radar )

HKWorkoutSession cannot be stopped: Workout session is not current
 
 
Q