Mac shutdown is calling PacketTunnelProvider::stopTunnelWithReason

MacOS Version: 14.3 (23D56)

In my testing of PacketTunnelProvider on MacOS I have observed that when I do a system shutdown or reboot, PacketTunnelProvider::stopTunnelWithReason() is getting called with reason: NEProviderStopReasonUserInitiated. Note: when I try to disconnect the VPN from system settings PacketTunnelProvider::stopTunnelWithReason() is called with the same reason: NEProviderStopReasonUserInitiated.

I am facing an issue here to identify what caused PacketTunnelProvider::stopTunnelWithReason(), system shutdown or any user action?

Replies

identify what caused [this]] system shutdown or any user action?

I don’t think there’s a good way to do that. It kinda makes sense really. Shut downs are user initiates after all.

If you want a specific API for this, I recommend that you file an enhancement request again Network Extension. Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

@eskimo I have filed an enhancement request: FB13771312.

For now is there a way (API) to figure out if the system is under shutdown. I can use that API to check inside PacketTunnelProvider::stopTunnelWithReason() if system is under shutdown.

FB13771312

Thanks for that.

For now is there a way (API) to figure out if the system is under shutdown.

No. That’s why I wrote “I don’t think there’s a good way to do that.”

I want to emphasise the good in that sentence. If you search the ’net you’ll likely find lots of bad suggestions for doing this. I recommend that you think carefully before relying on things that could be considered implementation details.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"