Skip to content

Conversation

@IanButterworth
Copy link
Member

When require_stdlib is called with an extension and the 'from' module is not from the bundled depot (from_stdlib=false), start_loading was not called but end_loading was still called in the finally block, causing a KeyError when trying to pop from package_locks.

Track whether start_loading was called and only call end_loading when appropriate.

Fixes #60392

Reproducer (test added):

% julia +1.11.8 --startup-file=no -e '
    Pkg_pkgid = Base.PkgId(Base.UUID("44cfe95a-1eb2-52ea-b672-e2afdf69b78f"), "Pkg")
    REPLExt_pkgid = Base.PkgId(Base.uuid5(Pkg_pkgid.uuid, "REPLExt"), "REPLExt")
    FakeREPL = Module(:REPL)
    FakeREPL_pkgid = Base.PkgId(Base.UUID("3fa0cd96-eef1-5676-8a61-b3b8758bbffb"), "REPL")
    Base.register_root_module(FakeREPL)
    Base.require_stdlib(Pkg_pkgid, "REPLExt", FakeREPL)
    Base.maybe_root_module(REPLExt_pkgid) isa Module || error("")
    println("Success!")
'
ERROR: KeyError: key Base.PkgId(Base.UUID("e5eb5ef1-03cf-53a7-ae1d-5a66b08e832b"), "REPLExt") not found
Stacktrace:
 [1] pop!
   @ ./dict.jl:583 [inlined]
 [2] end_loading
   @ ./loading.jl:2140 [inlined]
 [3] macro expansion
   @ ./loading.jl:2724 [inlined]
 [4] macro expansion
   @ ./lock.jl:273 [inlined]
 [5] require_stdlib(package_uuidkey::Base.PkgId, ext::String, from::Module)
   @ Base ./loading.jl:2689
 [6] top-level scope
   @ none:7

When require_stdlib is called with an extension and the 'from' module
is not from the bundled depot (from_stdlib=false), start_loading was
not called but end_loading was still called in the finally block,
causing a KeyError when trying to pop from package_locks.

Track whether start_loading was called and only call end_loading when
appropriate.

Fixes JuliaLang#60392

Co-authored-by: Claude <[email protected]>
@IanButterworth IanButterworth changed the title Fix KeyError in require_stdlib for non-stdlib extensions [release-1.11] Fix KeyError in require_stdlib for non-stdlib extensions Dec 26, 2025
@IanButterworth
Copy link
Member Author

@DilumAluthge @KristofferC I believe this is relatively urgent?

@DilumAluthge
Copy link
Member

I've recreated the backports-release-1.11 branch.

@DilumAluthge DilumAluthge changed the base branch from release-1.11 to backports-release-1.11 January 4, 2026 06:30
@DilumAluthge
Copy link
Member

@vtjnash Would you be able to review this?

@DilumAluthge
Copy link
Member

I tested this PR locally, and at least for me it seems to fix the issue reported in #60392.

On Julia 1.11.8 (with using Revise in startup.jl):

$ julia +1.11
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.11.8 (2025-11-06)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

(@v1.11) pkg> Unhandled Task ERROR: KeyError: key Base.PkgId(Base.UUID("e5eb5ef1-03cf-53a7-ae1d-5a66b08e832b"), "REPLExt") not found
Stacktrace:
 [1] pop!
   @ ./dict.jl:583 [inlined]
 [2] end_loading
   @ ./loading.jl:2140 [inlined]
 [3] macro expansion
   @ ./loading.jl:2724 [inlined]
 [4] macro expansion
   @ ./lock.jl:273 [inlined]
 [5] require_stdlib(package_uuidkey::Base.PkgId, ext::String, from::Module)
   @ Base ./loading.jl:2689
 [6] load_pkg()
   @ REPL ~/juliaup.depot/juliaup/julia-1.11.8+0.aarch64.apple.darwin14/share/julia/stdlib/v1.11/REPL/src/Pkg_beforeload.jl:8
 [7] (::REPL.var"#123#141"{REPL.LineEdit.MIState, REPL.LineEditREPL, REPL.LineEdit.Prompt})()
   @ REPL ~/juliaup.depot/juliaup/julia-1.11.8+0.aarch64.apple.darwin14/share/julia/stdlib/v1.11/REPL/src/REPL.jl:1284

Using this PR:

$ julia +pr60491
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.11.8 (2025-12-26)
 _/ |\__'_|_|_|\__'_|  |  IanButterworth:ib/1.11_fix_require_stdlib/37e76389047 (fork: 730 commits, 688 days)
|__/                   |

(@v1.11) pkg> st
Status `~/.julia/environments/v1.11/Project.toml`
  [295af30f] Revise v3.13.0

(@v1.11) pkg>

Copy link
Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

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

SGTM

@IanButterworth IanButterworth merged commit deb1167 into JuliaLang:backports-release-1.11 Jan 5, 2026
7 checks passed
@IanButterworth IanButterworth deleted the ib/1.11_fix_require_stdlib branch January 5, 2026 16:22
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