Skip to content

Comments

Fix for closing TUN on Android#8471

Merged
jigar-f merged 1 commit intomainfrom
myles/reflog-android-crash
Feb 17, 2026
Merged

Fix for closing TUN on Android#8471
jigar-f merged 1 commit intomainfrom
myles/reflog-android-crash

Conversation

@myleshorton
Copy link
Contributor

@myleshorton myleshorton commented Feb 16, 2026

Fixes https://github.com/getlantern/engineering/issues/2997

This pull request improves the reliability and safety of shutting down the VPN service by adding a dedicated, synchronized method for closing the TUN interface file descriptor. This change helps prevent resource leaks and potential networking issues caused by the TUN interface remaining open due to race conditions during service shutdown.

Resource management and shutdown improvements:

  • Added a new closeTunInterface method to safely and synchronously close the TUN interface file descriptor, ensuring it is not closed multiple times from concurrent shutdown paths.
  • Updated onDestroy, postServiceClose, and doStopVPN to use the new closeTunInterface method instead of directly closing or nullifying mInterface, preventing orphaned TUN interfaces and possible routing issues. [1] [2] [3]

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes a race condition during Android VPN service shutdown that could leave the TUN interface open, causing network traffic to be routed into a "black hole." The fix introduces a synchronized method for closing the TUN interface file descriptor and updates all call sites to use it.

Changes:

  • Added a synchronized closeTunInterface() method to safely close the TUN interface and prevent double-close from concurrent shutdown paths
  • Updated onDestroy() to close TUN interface synchronously before cancelling the coroutine scope, preventing orphaned TUN interfaces
  • Replaced direct TUN interface operations in postServiceClose() and doStopVPN() with the new synchronized method

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@myleshorton myleshorton requested a review from jigar-f February 16, 2026 20:38
Copy link
Contributor

@jigar-f jigar-f left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I can think of a few more improvements, but Wil make it on other PR, Thanks

@jigar-f jigar-f merged commit 2f70af4 into main Feb 17, 2026
15 checks passed
@jigar-f jigar-f deleted the myles/reflog-android-crash branch February 17, 2026 06:44
atavism added a commit that referenced this pull request Feb 17, 2026
* Hide onboarding and datacap in ios  (#8466)

* Hide onboarding page and datacap in ios and update build number

* code review updates

* Garmr/ipc auth update (#8468)

* pull in radiance changes

* remove exclude arch in debug mode

* Update to latest radiance with no DNSTT since its breaking stuff (#8470)

* build and release updates (#8455)

* add safe area in plans

* Fix tablet upscaling and cap shared component sizing (#8457)

* update design size for tablets

* add cap scaling

* update mintextadapt

* logo updates and clean-ups

* update text fields

* clean-ups

* clean-ups

* fix scaling issue

---------

Co-authored-by: Jigar-f <jigar@getlantern.org>

* Fix for closing TUN (#8471)

* Fix stage env toggle and store gating

* Narrow followups to staging env

* Enable Play store uploads for internal Android releases (#8467)

* add support for internal Android releases

* use correct name for internal track

* update r0adkll/upload-google-play

* Fix track name

* update versionCode

* update foreground service permission

* disable exact alarm

---------

Co-authored-by: jigar-f <132374182+jigar-f@users.noreply.github.com>
Co-authored-by: garmr-ulfr <104022054+garmr-ulfr@users.noreply.github.com>
Co-authored-by: Jigar-f <jigar@getlantern.org>
Co-authored-by: Myles Horton <afisk@getlantern.org>
Co-authored-by: Jay <110402935+jay-418@users.noreply.github.com>
jigar-f added a commit that referenced this pull request Feb 20, 2026
* work for stage env

* update var name

* use output var

* set output

* Update nightly.yml

* try to use as env variable

* Update build-macos.yml

* update name

* Remove stage for now & add default value

* keep default and pass value

* Simplify macos changes

* Remove stage again

* More debugging

* compare it as string

* added debug log

* update radiance.

* updated radiance

* update radiance

* use remote source

* more stage changes

* use radiance remote

* Add stage env connection.

* Revert workflows

* generate ffi

* use radiance remote and remove duplication logic

* ran make format

* use in app purchase for macos.

* back to storekit one.

* Switch to user on acknowledge purchase if found.

* use new radiance.

* update radiance.

* do not clear all data

* Harden stage environment toggle and env normalization (#8475)

* Hide onboarding and datacap in ios  (#8466)

* Hide onboarding page and datacap in ios and update build number

* code review updates

* Garmr/ipc auth update (#8468)

* pull in radiance changes

* remove exclude arch in debug mode

* Update to latest radiance with no DNSTT since its breaking stuff (#8470)

* build and release updates (#8455)

* add safe area in plans

* Fix tablet upscaling and cap shared component sizing (#8457)

* update design size for tablets

* add cap scaling

* update mintextadapt

* logo updates and clean-ups

* update text fields

* clean-ups

* clean-ups

* fix scaling issue

---------

Co-authored-by: Jigar-f <jigar@getlantern.org>

* Fix for closing TUN (#8471)

* Fix stage env toggle and store gating

* Narrow followups to staging env

* Enable Play store uploads for internal Android releases (#8467)

* add support for internal Android releases

* use correct name for internal track

* update r0adkll/upload-google-play

* Fix track name

* update versionCode

* update foreground service permission

* disable exact alarm

---------

Co-authored-by: jigar-f <132374182+jigar-f@users.noreply.github.com>
Co-authored-by: garmr-ulfr <104022054+garmr-ulfr@users.noreply.github.com>
Co-authored-by: Jigar-f <jigar@getlantern.org>
Co-authored-by: Myles Horton <afisk@getlantern.org>
Co-authored-by: Jay <110402935+jay-418@users.noreply.github.com>

* Revert back some changes

* Fix issue with stage

* Fix stage issue on windows

* update logs

* revert back macos in app purchase changes

---------

Co-authored-by: atavism <atavism@users.noreply.github.com>
Co-authored-by: garmr-ulfr <104022054+garmr-ulfr@users.noreply.github.com>
Co-authored-by: Myles Horton <afisk@getlantern.org>
Co-authored-by: Jay <110402935+jay-418@users.noreply.github.com>
Co-authored-by: atavism <paul@getlantern.org>
atavism added a commit that referenced this pull request Feb 20, 2026
* work for stage env

* update var name

* use output var

* set output

* Update nightly.yml

* try to use as env variable

* Update build-macos.yml

* update name

* Remove stage for now & add default value

* keep default and pass value

* Simplify macos changes

* Remove stage again

* More debugging

* compare it as string

* added debug log

* update radiance.

* updated radiance

* update radiance

* use remote source

* more stage changes

* use radiance remote

* Add stage env connection.

* Revert workflows

* generate ffi

* use radiance remote and remove duplication logic

* ran make format

* use in app purchase for macos.

* back to storekit one.

* Switch to user on acknowledge purchase if found.

* use new radiance.

* update radiance.

* do not clear all data

* Harden stage environment toggle and env normalization (#8475)

* Hide onboarding and datacap in ios  (#8466)

* Hide onboarding page and datacap in ios and update build number

* code review updates

* Garmr/ipc auth update (#8468)

* pull in radiance changes

* remove exclude arch in debug mode

* Update to latest radiance with no DNSTT since its breaking stuff (#8470)

* build and release updates (#8455)

* add safe area in plans

* Fix tablet upscaling and cap shared component sizing (#8457)

* update design size for tablets

* add cap scaling

* update mintextadapt

* logo updates and clean-ups

* update text fields

* clean-ups

* clean-ups

* fix scaling issue

---------

Co-authored-by: Jigar-f <jigar@getlantern.org>

* Fix for closing TUN (#8471)

* Fix stage env toggle and store gating

* Narrow followups to staging env

* Enable Play store uploads for internal Android releases (#8467)

* add support for internal Android releases

* use correct name for internal track

* update r0adkll/upload-google-play

* Fix track name

* update versionCode

* update foreground service permission

* disable exact alarm

---------

Co-authored-by: jigar-f <132374182+jigar-f@users.noreply.github.com>
Co-authored-by: garmr-ulfr <104022054+garmr-ulfr@users.noreply.github.com>
Co-authored-by: Jigar-f <jigar@getlantern.org>
Co-authored-by: Myles Horton <afisk@getlantern.org>
Co-authored-by: Jay <110402935+jay-418@users.noreply.github.com>

* Revert back some changes

* Fix issue with stage

* Fix stage issue on windows

* update logs

* revert back macos in app purchase changes

---------

Co-authored-by: atavism <atavism@users.noreply.github.com>
Co-authored-by: garmr-ulfr <104022054+garmr-ulfr@users.noreply.github.com>
Co-authored-by: Myles Horton <afisk@getlantern.org>
Co-authored-by: Jay <110402935+jay-418@users.noreply.github.com>
Co-authored-by: atavism <paul@getlantern.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants