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

Use Foundation.ProcessInfo for environment parsing #573

Merged

Conversation

GNMoseke
Copy link
Contributor

Resolves #571

  • Simply replaces use of environ with Foundation.ProcessInfo

@Joannis
Copy link
Member

Joannis commented Sep 30, 2024

My only (slight) concern is that I believe this wasn't thread safe in 5.9

I don't know if it's still the case - or if it matters much at all. Would need to verify that

@GNMoseke
Copy link
Contributor Author

Yeah I saw that in the issue - I can verify in 5.9, will draft this guy for now.

@GNMoseke GNMoseke marked this pull request as draft September 30, 2024 07:38
Copy link

codecov bot commented Sep 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.68%. Comparing base (e78cde7) to head (94ae83f).
Report is 144 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #573      +/-   ##
==========================================
- Coverage   84.86%   83.68%   -1.19%     
==========================================
  Files          98       99       +1     
  Lines        5320     4406     -914     
==========================================
- Hits         4515     3687     -828     
+ Misses        805      719      -86     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@GNMoseke GNMoseke force-pushed the fix/use-foundation-environment branch from 564f624 to 0350eed Compare September 30, 2024 07:40
@GNMoseke
Copy link
Contributor Author

At least as of 5.9.1, the implementation of ProcessInfo.processInfo.environment is the same as what this PR replaces - so there should be no difference for 5.9

The underlying access is indeed a char** as @adam-fowler commented in the original issue - I am sorry to say that my low-level cpp knowledge isn't super strong, so this appears thread safe to me, but take that with a grain of salt

@GNMoseke GNMoseke marked this pull request as ready for review September 30, 2024 08:00
Joannis
Joannis previously approved these changes Sep 30, 2024
Copy link
Member

@Joannis Joannis left a comment

Choose a reason for hiding this comment

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

Hmm, you're right. I just looked it up: environ is not thread safe. Happy to accept this change, but we'll need synchronisation it seems.

Copy link
Member

@Joannis Joannis left a comment

Choose a reason for hiding this comment

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

Hmm, you're right. I just looked it up: environ is not thread safe. Happy to accept this change, but we'll need synchronisation it seems.

Sources/Hummingbird/Environment.swift Outdated Show resolved Hide resolved
@GNMoseke GNMoseke force-pushed the fix/use-foundation-environment branch from 0350eed to a6835e0 Compare September 30, 2024 08:18
adam-fowler
adam-fowler previously approved these changes Sep 30, 2024
Copy link
Member

@adam-fowler adam-fowler left a comment

Choose a reason for hiding this comment

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

Given this is replacing like for like and in Swift 6 processInfo.environment is thread safe I'm happy to accept this PR. We can discuss any synchronisation support for 5.x in another PR. Plus we should verify it is an issue.

@adam-fowler adam-fowler dismissed their stale review September 30, 2024 09:07

I retract my approval as we have a failure in the tests

@Joannis Joannis dismissed their stale review September 30, 2024 11:31

Test failure

@GNMoseke GNMoseke marked this pull request as draft September 30, 2024 14:43
@GNMoseke
Copy link
Contributor Author

GNMoseke commented Oct 5, 2024

Alright fellas sorry it took me so long to get back to this - as mentioned in #574 there's some thread safety issues here.

I think what was happening is that ProcessInfo.processInfo, as a static variable, along with Environment.getEnvironment as a static method were doing something funky when all tests were run in a single process (from a normal swift test invocation). About 1/5 times there I could reproduce the failure, including on a 6.0.1 toolchain.

I could not reproduce the failure running swift test --parallel, which is what leads me to believe that this only pops up in the case where all the tests are being started from the same process.

As a band-aid I renamed the env var that testSetForAllEnvironments uses, which feels like a bit of a hacky solution but does resolve the test failure.

All of the above said, I am very new to the codebase here and could absolutely be misunderstanding what's happening, so if any of that^ is untrue, please call me on it.

TL;DR I don't think this is actually an issue in a real running hummingbird instance since the server is started as a single process and the environment is being properly mutated - just a race in tests.

@GNMoseke GNMoseke marked this pull request as ready for review October 5, 2024 08:04
@GNMoseke GNMoseke force-pushed the fix/use-foundation-environment branch from 1ceae90 to 94ae83f Compare October 5, 2024 08:19
@adam-fowler
Copy link
Member

As a band-aid I renamed the env var that testSetForAllEnvironments uses, which feels like a bit of a hacky solution but does resolve the test failure.

I think this is fine. The tests should be treated as independent and not affect each other.

@GNMoseke GNMoseke requested a review from Joannis October 5, 2024 09:35
@adam-fowler adam-fowler merged commit 913e6a0 into hummingbird-project:main Oct 5, 2024
6 of 9 checks passed
@GNMoseke GNMoseke deleted the fix/use-foundation-environment branch October 5, 2024 17:52
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.

Use ProcessInfo.processInfo.environment instead of environ.
3 participants