Skip to content

fix: detach tun fd ownership to prevent fdsan double-close crash#23

Merged
Itsusinn merged 2 commits into
mainfrom
fix/fd-crash
Jun 15, 2026
Merged

fix: detach tun fd ownership to prevent fdsan double-close crash#23
Itsusinn merged 2 commits into
mainfrom
fix/fd-crash

Conversation

@Itsusinn

Copy link
Copy Markdown
Member

Problem

App crashes with fdsan: attempted to close file descriptor X, expected to be unowned, actually owned by ParcelFileDescriptor on shutdown, leading to SIGABRT.

Root cause

The TUN file descriptor was shared between Kotlin and Rust — both sides tried to close() it. Android's fdsan detects this double-close and kills the process.

Fix

Use ParcelFileDescriptor.detachFd() instead of .fd when passing the FD to Rust. This transfers FD ownership to the Rust side; subsequent vpnInterface?.close() in cleanup becomes a no-op for the real FD.

Commits

  • a375296 fix: detach tun fd ownership to prevent fdsan double-close crash
  • ed5de63 chore: bump version to 0.4.1

Itsusinn added 2 commits June 15, 2026 19:11
Use ParcelFileDescriptor.detachFd() instead of .fd when passing the
TUN file descriptor to Rust. This transfers FD ownership to the Rust
side, so the subsequent vpnInterface?.close() in cleanup() no longer
closes the same FD — avoiding the fdsan SIGABRT.

"fdsan: attempted to close file descriptor X, expected to be unowned,
actually owned by ParcelFileDescriptor"

Signed-off-by: iHsin <sun@ihsin.dev>
Assisted-by: OpenClaw:deepseek-v4-flash
Signed-off-by: iHsin <sun@ihsin.dev>
@Itsusinn
Itsusinn merged commit 5cec255 into main Jun 15, 2026
1 check passed
@Itsusinn
Itsusinn deleted the fix/fd-crash branch June 15, 2026 12:10
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.

1 participant