This repository has been archived by the owner on Sep 29, 2024. It is now read-only.
Fixed "Index out of range" bug in control channel #143
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi there!
The bug story
I've tried to establish a VPN connection from iOS device to my test VPN server with SoftEther on board. SoftEhter declares, that it supports openvpn protocol (and it really does).
However, when I built and setup all things, soon after connection in the Demo app, I got a disconnected state.
I've analyzed the logs, and it seems that at some moment of time the runtime error "Index out of range" occures inside network extension, which causes network session daemon to unload this extension and drop connection.
After adding some debug logs I found a place with the problem: we are iterating the queue with packets, deleting the packet from it at the same time. So after deleting we have a problem with array indexes.
The fix
This is a well-known problem, and as far as I could say, in Swift the common solution is to iterate over reversed array, so index changing would not affect any next elements, which I implemented here.