Skip to content

feat(apple): use .zip for logs - #9536

Merged
jamilbk merged 6 commits into
mainfrom
feat/apple-zipped-logs
Jun 23, 2025
Merged

jamilbk merged 6 commits into
mainfrom
feat/apple-zipped-logs

Conversation

@thomaseizinger

@thomaseizinger thomaseizinger commented Jun 15, 2025 •

Copy link
Copy Markdown
Member

This PR replaces the use of Apple Archive with an API that allows us to zip the log file contents. This API doesn't handle symlinks well so we move the symlink out of the way before making the zip. The symlink is then moved back after the process is completed. Any errors in this process are ignored as the symlink itself is not a critical component of Firezone.

The zip compression is marginally less efficient than the Apple Archive. Instead of compressing ~2GB of logs to 11.8 MB we now get an archive of 12.4 MB. Considering how much easier zip files are to handle, this seems like a fine trade-off.

Screenshot 2025-06-16 at 00 04 52

Resolves: #7475

@thomaseizinger
thomaseizinger requested a review from jamilbk June 15, 2025 16:25
@vercel

vercel Bot commented Jun 15, 2025 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
firezone ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 23, 2025 10:21pm

@jamilbk

jamilbk commented Jun 15, 2025

Copy link
Copy Markdown
Member

Hmm yeah, zip is one of those things that is "done" so we could probably vendor an implementation here. The last (and most popular) zip library we used here had a security issue which is what prompted me to remove it, and Dependabot still can't update Swift (!!).

@thomaseizinger

Copy link
Copy Markdown
Member Author

Looking at the Sentry report, the issue is in fact no file-size but the "latest" symlink.

@thomaseizinger

Copy link
Copy Markdown
Member Author

Looking at the Sentry report, the issue is in fact no file-size but the "latest" symlink.

Actually, this works completely fine if the symlink is not there. Maybe I can skip it from being exported?

@jamilbk

jamilbk commented Jun 15, 2025

Copy link
Copy Markdown
Member

Looking at the Sentry report, the issue is in fact no file-size but the "latest" symlink.

Actually, this works completely fine if the symlink is not there. Maybe I can skip it from being exported?

That should probably be fine. The current export follows the link which includes the file twice.

Comment on lines 37 to 45

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@jamilbk I've put the handling of the latest symlink in here because this needs to happen on iOS too and I didn't want to duplicate it on both callsites. I think the more complete / robust approach would be to scan the entire directory for symlinks and move them away before creating the archive.

At this point though, we only have a single symlink so it seems fine to me to take this shortcut.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This wasn't pointing to the connlib directory but to the parent logs directory.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be reverted because it will skip any Swift logs we make in the Network Extension

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this comment is still relevant? Looks like the export doesn't include any Swift logs from the tunnel here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh, didn't realise that. If we change the path back you need to adjust the path to the sym link.

@thomaseizinger
thomaseizinger force-pushed the feat/apple-zipped-logs branch from 76edc81 to 4b82da0 Compare June 15, 2025 22:16
@thomaseizinger
thomaseizinger marked this pull request as ready for review June 15, 2025 22:16
@thomaseizinger

Copy link
Copy Markdown
Member Author

@jamilbk Would appreciate if you could test this on an iOS device.

@jamilbk

jamilbk commented Jun 17, 2025

Copy link
Copy Markdown
Member

Getting this on iOS:

Upload preparation for claim 5F5BCE66-F56C-43F9-94FB-55D20D7B48F1 completed with error: Error Domain=NSCocoaErrorDomain Code=260 "The file “latest” couldn’t be opened because there is no such file." UserInfo={NSURL=file:///private/var/mobile/Containers/Shared/AppGroup/A2A666F6-06FE-481D-9F75-C07CFEAC463A/Library/Caches/logs/connlib/latest, NSUnderlyingError=0x117932bb0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
Claim 5F5BCE66-F56C-43F9-94FB-55D20D7B48F1 failed during preparing for uploading due to error: Error Domain=NSCocoaErrorDomain Code=260 "The file “latest” couldn’t be opened because there is no such file." UserInfo={NSURL=file:///private/var/mobile/Containers/Shared/AppGroup/A2A666F6-06FE-481D-9F75-C07CFEAC463A/Library/Caches/logs/connlib/latest, NSUnderlyingError=0x117932bb0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
Received error updating telemetry: Connection interrupted

@jamilbk jamilbk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Having issues on iOS

  • Something is still trying to access the latest symlink
  • Clearing logs and then exporting on iOS causes a crash

I'll see if I can find some time in the coming days to push up fixes for the above

@thomaseizinger

Copy link
Copy Markdown
Member Author

Getting this on iOS:

Upload preparation for claim 5F5BCE66-F56C-43F9-94FB-55D20D7B48F1 completed with error: Error Domain=NSCocoaErrorDomain Code=260 "The file “latest” couldn’t be opened because there is no such file." UserInfo={NSURL=file:///private/var/mobile/Containers/Shared/AppGroup/A2A666F6-06FE-481D-9F75-C07CFEAC463A/Library/Caches/logs/connlib/latest, NSUnderlyingError=0x117932bb0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
Claim 5F5BCE66-F56C-43F9-94FB-55D20D7B48F1 failed during preparing for uploading due to error: Error Domain=NSCocoaErrorDomain Code=260 "The file “latest” couldn’t be opened because there is no such file." UserInfo={NSURL=file:///private/var/mobile/Containers/Shared/AppGroup/A2A666F6-06FE-481D-9F75-C07CFEAC463A/Library/Caches/logs/connlib/latest, NSUnderlyingError=0x117932bb0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
Received error updating telemetry: Connection interrupted

This is the same error I had on macOS. Probably the logic for moving the latest file doesn't work. I am moving it to the parent directory which might not work on iOS?

@thomaseizinger

Copy link
Copy Markdown
Member Author

Getting this on iOS:

Upload preparation for claim 5F5BCE66-F56C-43F9-94FB-55D20D7B48F1 completed with error: Error Domain=NSCocoaErrorDomain Code=260 "The file “latest” couldn’t be opened because there is no such file." UserInfo={NSURL=file:///private/var/mobile/Containers/Shared/AppGroup/A2A666F6-06FE-481D-9F75-C07CFEAC463A/Library/Caches/logs/connlib/latest, NSUnderlyingError=0x117932bb0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
Claim 5F5BCE66-F56C-43F9-94FB-55D20D7B48F1 failed during preparing for uploading due to error: Error Domain=NSCocoaErrorDomain Code=260 "The file “latest” couldn’t be opened because there is no such file." UserInfo={NSURL=file:///private/var/mobile/Containers/Shared/AppGroup/A2A666F6-06FE-481D-9F75-C07CFEAC463A/Library/Caches/logs/connlib/latest, NSUnderlyingError=0x117932bb0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
Received error updating telemetry: Connection interrupted

This is the same error I had on macOS. Probably the logic for moving the latest file doesn't work. I am moving it to the parent directory which might not work on iOS?

I guess this is because on iOS, we zip the entire log directory and therefore the latest symlink is in a subdir.

We could skip the creation of the symlink on iOS altogether as I think it won't be useful there anyway?

@thomaseizinger
thomaseizinger force-pushed the feat/apple-zipped-logs branch from dd8af45 to aec2e32 Compare June 18, 2025 07:43
@thomaseizinger

Copy link
Copy Markdown
Member Author

@jamilbk Could you test on iOS again? I've now disabled the latest symlink on iOS as it is unlikely that we are going to use it there anyway.

@jamilbk

jamilbk commented Jun 18, 2025

Copy link
Copy Markdown
Member

Seeing this on iOS still. Will look further into it

Failed to request default share mode for fileURL:file:///private/var/mobile/Containers/Data/Application/597FA252-3F28-49E4-AD71-7475C5E1DCFC/tmp/firezone_logs_2025-06-18T153101Z.zip error:Error Domain=NSOSStatusErrorDomain Code=-10814 "(null)" UserInfo={_LSLine=1796, _LSFunction=runEvaluator}
Only support loading options for CKShare and SWY types.
error fetching item for URL:file:///private/var/mobile/Containers/Data/Application/597FA252-3F28-49E4-AD71-7475C5E1DCFC/tmp/firezone_logs_2025-06-18T153101Z.zip : (null)
error fetching file provider domain for URL:file:///private/var/mobile/Containers/Data/Application/597FA252-3F28-49E4-AD71-7475C5E1DCFC/tmp/firezone_logs_2025-06-18T153101Z.zip : (null)
error fetching item for URL:file:///private/var/mobile/Containers/Data/Application/597FA252-3F28-49E4-AD71-7475C5E1DCFC/tmp/firezone_logs_2025-06-18T153101Z.zip : (null)
Received port for identifier response: <(null)> with error:Error Domain=RBSServiceErrorDomain Code=1 "Client not entitled" UserInfo={RBSEntitlement=com.apple.runningboard.process-state, NSLocalizedFailureReason=Client not entitled, RBSPermanent=false}
elapsedCPUTimeForFrontBoard couldn't generate a task port

@thomaseizinger
thomaseizinger force-pushed the feat/apple-zipped-logs branch from eaf310b to d8fcfdc Compare June 23, 2025 16:07
@thomaseizinger thomaseizinger changed the title feat(apple): use .zip for logs feat(apple): use .zip for logs on MacOS Jun 23, 2025
@thomaseizinger

Copy link
Copy Markdown
Member Author

@jamilbk I've updated this to only use .zip on MacOS now. iOS will still use .aar. We don't have that many customers on iOS so just getting this out on MacOS would already be a win.

@jamilbk jamilbk left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I actually think the iOS zip export was working - upon further investigation the logs were exported, but the errors shown seem to do with development builds only.

On macOS, we're not getting any tunnel/ logs from the Swift side.

I can push a commit up to fix the above since I can test on iOS.

@jamilbk

jamilbk commented Jun 23, 2025 •

Copy link
Copy Markdown
Member

We don't have that many customers on iOS so just getting this out on MacOS would already be a win.

True, but it's not far behind - I know we have a handful largish customers relying on iOS at the moment.

@thomaseizinger

Copy link
Copy Markdown
Member Author

I actually think the iOS zip export was working - upon further investigation the logs were exported, but the errors shown seem to do with development builds only.

On macOS, we're not getting any tunnel/ logs from the Swift side.

I can push a commit up to fix the above since I can test on iOS.

Oh okay, yeah feel free to take over from here. Adapting the iOS code shouldn't been too difficult. We just need to delete the symlink again.

@thomaseizinger
thomaseizinger disabled auto-merge June 23, 2025 20:04
@jamilbk

jamilbk commented Jun 23, 2025

Copy link
Copy Markdown
Member

We just need to delete the symlink again.

I think I can keep the symlink working, will just do the same thing as macOS by moving it out of the way temporarily.

@jamilbk jamilbk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Tested:

  • iOS: clearing + exporting logs
  • macOS: clearing + exporting logs

@jamilbk
jamilbk enabled auto-merge June 23, 2025 20:11
@thomaseizinger thomaseizinger changed the title feat(apple): use .zip for logs on MacOS feat(apple): use .zip for logs Jun 23, 2025
Signed-off-by: Thomas Eizinger <thomas@eizinger.io>
@jamilbk
jamilbk added this pull request to the merge queue Jun 23, 2025
Merged via the queue into main with commit f211c9d Jun 23, 2025
@jamilbk
jamilbk deleted the feat/apple-zipped-logs branch June 23, 2025 22:32

This branch was successfully deployed

1 active deployment
Preview — 62998bf4 Deployed Jun 23, 2025 by vercel[bot]
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.

Don't use .aar to pack logs

2 participants