Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-14033] [Linux] appendingPathComponent memory leak on linux #4380

Closed
swift-ci opened this issue Jan 10, 2021 · 2 comments
Closed

[SR-14033] [Linux] appendingPathComponent memory leak on linux #4380

swift-ci opened this issue Jan 10, 2021 · 2 comments

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-14033
Radar None
Original Reporter kolya-j (JIRA User)
Type Bug
Status Closed
Resolution Invalid

Attachment: Download

Environment

Running in docker using 5.3.2 bionic slim image. Here `printenv` result:
HOSTNAME=ea95b9e26193
SWIFT_WEBROOT=https://swift.org/builds/
SWIFT_VERSION=swift-5.3.2-RELEASE
SWIFT_PLATFORM=ubuntu18.04
PWD=/app
SWIFT_SIGNING_KEY=A62AE125BBBFBB96A6E042EC925CC1CCED3D1561
SWIFT_BRANCH=swift-5.3.2-release
HOME=/root
TERM=xterm
SHLVL=1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
_=/usr/bin/printenv

result of ` cat /etc/issue`
Ubuntu 18.04.5 LTS \n \l

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: aa2373e314ae1ce56856afcb4ac4360c

Issue Description:

If I run this code: no memory leak, app footprint and really small. 1.629MiB

let fileManager = FileManager.default

try? FileManager.default.createDirectory(at: URL(fileURLWithPath: "/app/logs", isDirectory: true),
                                         withIntermediateDirectories: false,
                                         attributes: nil)
for i in 0...200000 {
    let requestId = UUID().uuidString


    var logsFolderUrl = URL(fileURLWithPath: fileManager.currentDirectoryPath, isDirectory: true)
    logsFolderUrl = logsFolderUrl.appendingPathComponent("logs", isDirectory: true)
    _ = logsFolderUrl.appendingPathComponent(requestId + ".log", isDirectory: false)
}

But if I remove `isDirectory` parameter and run this -

let fileManager = FileManager.default


try? FileManager.default.createDirectory(at: URL(fileURLWithPath: "/app/logs", isDirectory: true),
                                         withIntermediateDirectories: false,
                                         attributes: nil)
for i in 0...200000 {
    let requestId = UUID().uuidString

    var logsFolderUrl = URL(fileURLWithPath: fileManager.currentDirectoryPath)
    logsFolderUrl = logsFolderUrl.appendingPathComponent("logs")
    _ = logsFolderUrl.appendingPathComponent(requestId + ".log")
}

Memory footpring become 93.61MiB .

This did cause a lot of issues in my app, where I did file logger for Vapor app.

I can reproduce it only on linux, on macOS no issue at all. Just in case I attached my main.swift file. Both codes are there. One is commented

@swift-ci
Copy link
Contributor Author

Comment by Nikolay Dzhulay (JIRA)

I will close this ticket. Issue is not in swift itself. Issue is in docker container, which is based on linux kit. Issue is caching of FS. If I understand it created 512 bytes for every file you create. Looks like event for checking existence of file, it create same 512B buffer.
It was painful way to figure this out. Thanks to this article: https://codefresh.io/docker-tutorial/docker-memory-usage/

I hope it will help anyone who in future will have the same issue.

@swift-ci
Copy link
Contributor Author

Comment by Nikolay Dzhulay (JIRA)

I added comment. Issue itself is linux FS caching

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant