SwiftLint leaks memory

Created on 9 Dec 2020  路  13Comments  路  Source: realm/SwiftLint

New Issue Checklist

Describe the bug

For some reason my swiftlint processes leak memory.

Screenshot 2020-12-09 at 21 34 29

Complete output when running SwiftLint, including the stack trace and command used

N/A, I'm using SwiftLint via the VSCode extension.

Environment

  • SwiftLint version (run swiftlint version to be sure)?
    0.41.0
  • Installation method used (Homebrew, CocoaPods, building from source, etc)?
    Homebrew
  • Paste your configuration file:
disabled_rules:
  - trailing_comma
  - identifier_name
  - void_return
  - operator_whitespace
  - nesting
  - cyclomatic_complexity

line_length:
  - 100
  - 140

function_body_length:
  - 50

excluded: # paths to ignore during linting. Takes precedence over `included`.
  - .build
  - Example/Pods
  - Tests/CoreXLSXTests/XCTestManifests.swift
  • Are you using nested configurations?
    No
  • Which Xcode version are you using (check xcodebuild -version)?
    Xcode 12.2
    Build version 12B45b
  • Do you have a sample that shows the issue?
    N/A, this happened with multiple different projects for me, but I'm not sure what exact code snippet triggers it.

Most helpful comment

It might be a SwiftLint bug, it depends if the VSCode extension is using SwiftLint in an unsupported way.

All 13 comments

Are you saying that once SwiftLint terminates it's still retaining memory? Or that the process of linting takes more memory than you'd expect? SwiftLint caches the contents of every file it's linting, and some indexes around them, that definitely contributes to significant memory usage.

It doesn't look like it terminates at all, I'll check CPU time next time I see this. But even with caching tens of gigabytes of memory consumed don't seem to be normal. I'm using that VSCode extension for quite a long time, and this started happening only recently, maybe after I upgraded to 0.41.0. I run brew upgrade regularly, but I don't remember when exactly I upgraded.

The fact that SwiftLint isn't terminating is more concerning. Can you reproduce this running it from the command line?

I ran swiftlint in CLI on the same project that caused this issue in VSCode, and it terminated normally (in a fraction of a second).

Got it now with CPU time, here you can see two processes running for minutes now. It's reproducible with CoreXLSX for me when I open and edit it in VSCode. I have it set up so that it runs SwiftLint every time I save a file in it.

Screenshot 2020-12-09 at 21 56 37

Also, these processes don't die after I close VSCode, and their CPU load sticks to about 10-20% on average. Maybe they're stuck in some kind of a loop when interacting with SourceKit, or something like that?

Given that this doesn't happen from the command line, but rather from the VSCode extension, can you please open an issue there? I'm not familiar with it and I don't know how they integrate with SwiftLint.

I can open it there, but I hope it also stays open here. Regardless of what the VSCode extension is doing, I feel that it's a bug that SwiftLint can be stuck in such state, if that makes sense?

It might be a SwiftLint bug, it depends if the VSCode extension is using SwiftLint in an unsupported way.

Hi. Presumably there has been a bug in the latest version of my extension. As a temporary hot fix I shipped an old version.

My guess: the extension runs SwiftLint from the wrong directory (maybe even root instead of the current folder!).
If it's true, SwiftLint handles it very well. Will report back once I know for sure the next days.

Sorry for the inconvenience.

I just had a look on the bug:

  • the extension started SwiftLint from the wrong directory which essentially linted many projects
  • the extension didn't kill SwiftLint when deactivated

=> SwiftLint does exactly what it has been told to do. No bug in this repo.

Awesome, thanks! This can be closed then.

Thanks for investigating!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

muzamilhassan1987 picture muzamilhassan1987  路  3Comments

zntfdr picture zntfdr  路  3Comments

larslockefeer picture larslockefeer  路  3Comments

bourquep picture bourquep  路  3Comments

BalestraPatrick picture BalestraPatrick  路  3Comments