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

Regex cache non thread-safe #1344

Closed
vincentisambart opened this issue Mar 8, 2017 · 3 comments · Fixed by #1347
Closed

Regex cache non thread-safe #1344

vincentisambart opened this issue Mar 8, 2017 · 3 comments · Fixed by #1347
Labels
bug Unexpected and reproducible misbehavior.

Comments

@vincentisambart
Copy link

When running SwiftLint on our code base, SwiftLint crashes pretty often.
I cannot send you our source code, but I was able to reproduce the problem even when running SwiftLint on its own source code from Xcode.

I'm running SwiftLint with the command line arguments lint --no-cache.

As it's a multi-threaded-related problem, it won't occur every time, but in Xcode's scheme settings, in the Diagnostic tabs, enable "Thread Sanitizer" and "Pause on issues" and the Thread Sanitizer should report the problem every time.

The problem is in NSRegularExpression+SwiftLint.swift. Even though multiple files are checked in parallel, the regex cache that all threads access is not multi-thread safe.

The best solution is probably one of the following:

  • Do not cache compiled regular expressions.
  • Make the regex cache thread-safe (for example using GCD).
  • Make the cache thread-local (probably need the most work).
@jonah-williams
Copy link

Thanks for digging into this. I haven't confirmed the root cause but I believe my current project is seeing the same issue as our number of linted files has grown.

If it helps anyone spot instances of the same: I'm seeing swiftlint crash intermittently with Segmentation fault: 11 "${SWIFT_LINT}" lint --path "${path}" --no-cache which then surfaces in Xcode as a Command /bin/sh failed with exit code 139 if you're running swiftlint as part of a run script build phase.

@jpsim jpsim added the bug Unexpected and reproducible misbehavior. label Mar 9, 2017
@jpsim
Copy link
Collaborator

jpsim commented Mar 9, 2017

Thanks for filing this. Should be a quick fix: #1347.

@vincentisambart
Copy link
Author

Thanks for the quick fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected and reproducible misbehavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants