Skip to content

Change Distributed.cluster_manager from a global non-constant ClusterManager to a global constant Ref{ClusterManager}#177

Merged
DilumAluthge merged 1 commit into
masterfrom
dpa/global-cluster_manager
Feb 20, 2026
Merged

Change Distributed.cluster_manager from a global non-constant ClusterManager to a global constant Ref{ClusterManager}#177
DilumAluthge merged 1 commit into
masterfrom
dpa/global-cluster_manager

Conversation

@DilumAluthge

Copy link
Copy Markdown
Member

No description provided.

@DilumAluthge

DilumAluthge commented Feb 13, 2026

Copy link
Copy Markdown
Member Author

@JamesWrigley It looks like this isn't sufficient to fix the JET error. Example CI log:

═════ 2 possible errors found ═════
┌ start_worker(cookie::AbstractString; kwargs...) @ Distributed /home/runner/work/Distributed.jl/Distributed.jl/src/cluster.jl:241
│┌ start_worker(out::IO, cookie::AbstractString) @ Distributed /home/runner/work/Distributed.jl/Distributed.jl/src/cluster.jl:242
││┌ start_worker(out::IO, cookie::AbstractString; close_stdin::Bool, stderr_to_stdout::Bool) @ Distributed /home/runner/work/Distributed.jl/Distributed.jl/src/cluster.jl:260
│││┌ Task(f::Distributed.var"#26#27") @ Base ./task.jl:5
││││┌ (::Distributed.var"#26#27")() @ Distributed /home/runner/work/Distributed.jl/Distributed.jl/src/cluster.jl:262
│││││┌ process_messages(r_stream::Base.PipeEndpoint, w_stream::Base.PipeEndpoint, incoming::Bool) @ Distributed /home/runner/work/Distributed.jl/Distributed.jl/src/process_messages.jl:151
││││││┌ Task(f::Distributed.var"#process_messages##2#process_messages##3"{Base.PipeEndpoint, Base.PipeEndpoint, Bool}) @ Base ./task.jl:5
│││││││┌ (::Distributed.var"#process_messages##2#process_messages##3"{Base.PipeEndpoint, Base.PipeEndpoint, Bool})() @ Distributed /home/runner/work/Distributed.jl/Distributed.jl/src/process_messages.jl:151
││││││││┌ message_handler_loop(r_stream::Base.PipeEndpoint, w_stream::Base.PipeEndpoint, incoming::Bool) @ Distributed /home/runner/work/Distributed.jl/Distributed.jl/src/process_messages.jl:164
│││││││││┌  @ Distributed /home/runner/work/Distributed.jl/Distributed.jl/src/process_messages.jl:319
││││││││││ `Distributed.cluster_manager` may be undefined: Distributed.cluster_manager
│││││││││└────────────────────
│││││││││┌  @ Distributed /home/runner/work/Distributed.jl/Distributed.jl/src/process_messages.jl:332
││││││││││ `Distributed.cluster_manager` may be undefined: Distributed.cluster_manager
│││││││││└────────────────────

Test Summary: | Fail  Total   Time
JET           |    1      1  11.0s

@DilumAluthge

Copy link
Copy Markdown
Member Author

That being said, this might still be a good change to make, because it makes it a bit more explicit that the global exists, and isa ClusterManager.

@DilumAluthge
DilumAluthge marked this pull request as ready for review February 13, 2026 00:10
@codecov

codecov Bot commented Feb 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.38%. Comparing base (6649a94) to head (d533b94).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #177      +/-   ##
==========================================
+ Coverage   79.34%   79.38%   +0.04%     
==========================================
  Files          10       10              
  Lines        1951     1955       +4     
==========================================
+ Hits         1548     1552       +4     
  Misses        403      403              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aviatesk

aviatesk commented Feb 14, 2026

Copy link
Copy Markdown
Member

JET reports whenever a global variable that might be uninitialized is used.
For local variables, as you mentioned on Slack, you can avoid reporting by adding statements like @assert @isdefined(target_var) "assertion to help the compiler and JET". However, this approach does not work for global variables due to various reasons. The two options to consider are:

  1. Review the code architecture and eliminate uninitialized global variable references: In this case, passing cluster_manager as an argument to each subroutine is a better approach, leading to a more functional and good coding pattern.
  2. Always initialize the global variable: If the above approach is not feasible due to issues like API compatibility, you can use Ref or similar containers to always initialize the global variable, avoiding the problem. For example:
const cluster_manager = Ref{ClusterManager}()

function subroutine()
    isassigned(cluster_manager) || error("cluster manager uninitialized")
    manager = cluster_manager[]
    # use `manager`
end

This approach does not fundamentally solve the code design issue but exploits JET's permissive reporting approach though.

@DilumAluthge

Copy link
Copy Markdown
Member Author

@JamesWrigley What do you think? Should we go with the Ref approach?

@DilumAluthge
DilumAluthge marked this pull request as draft February 15, 2026 03:06
@DilumAluthge
DilumAluthge force-pushed the dpa/global-cluster_manager branch from 1ba667e to aa41d8b Compare February 20, 2026 11:06
@DilumAluthge DilumAluthge changed the title Declare cluster_manager as a global non-constant variable with a type declaration (albeit an abstract type) Change Distributed.cluster_manager from a global non-constant ClusterManager to a global constant Ref{ClusterManager} Feb 20, 2026

@JamesWrigley JamesWrigley 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.

Sorry for the late review 😬 LGTM!

@JamesWrigley

Copy link
Copy Markdown
Member

I think this is still an improvement over the previous code.

@DilumAluthge
DilumAluthge marked this pull request as ready for review February 20, 2026 12:04
@DilumAluthge

Copy link
Copy Markdown
Member Author

@JamesWrigley Do you think this is a breaking change? We've changed the type of Distributed.cluster_manager from ClusterManager to Ref{ClusterManager}, and users would now need to do Distributed.cluster_manager[] instead of Distributed.cluster_manager.

Is Distributed.cluster_manager part of the public API?

…terManager` to a global constant `Ref{ClusterManager}`
@DilumAluthge
DilumAluthge force-pushed the dpa/global-cluster_manager branch from 8a77120 to d533b94 Compare February 20, 2026 12:26
@JamesWrigley

Copy link
Copy Markdown
Member

I'm pretty sure it isn't 🤔 It's not in the docs at least. @vchuravy, @jpsamaroo what do you think?

@DilumAluthge
DilumAluthge merged commit 2fe1aa4 into master Feb 20, 2026
8 checks passed
@DilumAluthge
DilumAluthge deleted the dpa/global-cluster_manager branch February 20, 2026 13:18
@DilumAluthge

Copy link
Copy Markdown
Member Author

We can revert if @vchuravy or @jpsamaroo think this is breaking.

DilumAluthge added a commit to JuliaParallel/DistributedNext.jl that referenced this pull request Feb 22, 2026
…terManager` to a global constant `Ref{ClusterManager}` (#177)

This is a forward-port of JuliaLang/Distributed.jl#177 (JuliaLang/Distributed.jl@2fe1aa4).

(cherry picked from commit 2fe1aa4e267517565e99cd06664550dcd230cfc6)
DilumAluthge added a commit to JuliaLang/julia that referenced this pull request Feb 22, 2026
mkitti pushed a commit to mkitti/julia that referenced this pull request May 22, 2026
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.

3 participants