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?

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"

Hi, I hit the same issue. I need to know if the tunnel is being stopped because of a user action or because of a shutdown.

The reason "userLogout" is better suited for system shutdown imho.

It kinda makes sense really. Shut downs are user initiates after all.

Technically yes, but the user intent is different. In one case the user explicitly wants the VPN off, the other case it is an indirect consequence of another action.

Anyway I opened another ticket FB15711899 , because I can't see the status of the one opened by macnd.

Mac shutdown is calling PacketTunnelProvider::stopTunnelWithReason
 
 
Q