Fix param accessor usage in SetServerDefaults causing port 0 in URLs#3042
Conversation
|
Just to keep track of the impact AI-generated code is having on repo maintainability, I suspect this is another regression coming from a co-pilot feature that was merged without a second human review: |
b82c89d to
1f48694
Compare
1f48694 to
be9fbc5
Compare
- SetDefault operations only set values if they don't already have a value. Since the first call at line 1497 already set all the defaults, the second call was completely redundant for configuration purposes. - This duplicate SetServerDefaults call was introduced in PR #2869 - Allow configuration to be mutable at runtime. It intended to pass the TestWriteOriginScitokensConfig test tripped up by the "port 0" problem. It was a temporary bypass so it should be removed when the permanent fix comes (in this PR).
be9fbc5 to
67df10c
Compare
|
@jhiemstrawisc This PR is a regression for #2869 That PR calls This port 0 problem is caused by using the atomic config before it gets refreshed, which is a different scenario than the "port number race condition" problem in concurrent tests. Could you provide a second review for this PR? |
|
@h2zh thanks for the poke, I'll take a look as soon as I'm able! |
jhiemstrawisc
left a comment
There was a problem hiding this comment.
Looks good to me! In fact, I checked git blame and it looks like I was both the one who added the comment for SetServerDefaults() that explains nothing in the function should do a param.Get, and also the one who did exactly that in this section of code you're fixing 🤓 Thanks for cleaning it up for me!
|
To be clear, I still think the AI did the wrong thing here, even though I own part of the original bug. Rather than read the comments at the top of the function to fix the bug as @h2zh does here, the AI found a workaround to get tests to pass. |
The warning says nothing in the function should use 'viper.Get*' or 'param.<blah>.Get* and it gives a good reason. Unfortunately, we were still doing exactly that! It turns out it wasn't actually too much of a problem until bugs compounded between PR PelicanPlatform#2869 and PR PelicanPlatform#3042, at which point it broke configuration.
The warning says nothing in the function should use 'viper.Get*' or 'param.<blah>.Get* and it gives a good reason. Unfortunately, we were still doing exactly that! It turns out it wasn't actually too much of a problem until bugs compounded between PR #2869 and PR #3042, at which point it broke configuration.
This writeup is generated by Copilot and heavily edited by @h2zh.
The story of this PR starts with a duplicate
SetServerDefaultscall introduced in #2869 . It intended to pass theTestWriteOriginScitokensConfigtest tripped up by the "port 0" problem. It was a temporary bypass so it should be removed when the permanent fix comes (in this PR).Problem:
SetServerDefaultswas usingparam.Origin_Port.GetInt()andparam.Cache_Port.GetInt()to construct URLs, but these read from the atomic config which hasn't been refreshed yet at that point. This caused port values to be 0 instead of the default 8443, breakingTestWriteOriginScitokensConfig.Changes
Fix param accessor usage: Replace
param.Origin_Port.GetInt()andparam.Cache_Port.GetInt()withv.GetInt(param.Origin_Port.GetName())andv.GetInt(param.Cache_Port.GetName())to read from the viper instance being configuredRemove duplicate call: Remove redundant
SetServerDefaultscall at line 1946 inInitServerThis aligns with the function's documented guideline:
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
fonts.googleapis.com/usr/local/bin/node node /home/REDACTED/work/pelican/pelican/web_ui/frontend/node_modules/.bin/next build ux_amd64/vet ap /yaml.v3@v3.0.1/apic.go /yaml.v3@v3.0.1/decode.go ux_amd64/vet -I ache/go/1.24.12//home/REDACTED/work/pelican/pelican/web_ui/frontend/node_modules/.bin/�� -I ux_amd64/vet bin/�� x64/src/os/user -o ux_amd64/vet /tmp/cc9nTXZC.s g/protobuf/encod-c -o ux_amd64/vet(dns block)scarf.sh/usr/local/bin/node node ./report.js(dns block)topology.opensciencegrid.org/tmp/go-build1201400828/b001/xrootd.test /tmp/go-build1201400828/b001/xrootd.test -test.testlogfile=/tmp/go-build1201400828/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true -test.run=^(TestOSDFAuthRetrieval|TestAuthPathCompToWord|TestConstructAuthEntry|TestAuthPrivilegesFromWord|TestAuthPoliciesFromLine|TestPopulateAuthLinesMapForOrigin|TestPopulateAuthLinesMapForCache|TestSerializeAuthline|TestGetSortedSerializedAuthLines|T /httprouter@v1.3-ifaceassert ux_amd64/vet get er32/adler32.go x64/pkg/tool/lin-o ux_amd64/vet -uns�� @v1.0.0/proto.go @v1.0.0/varint.go ux_amd64/vet g_.a tobuf_extensions/pbutil ache/go/1.24.12/-importcfg ux_amd64/vet(dns block)/tmp/go-build3929737176/b001/xrootd.test /tmp/go-build3929737176/b001/xrootd.test -test.testlogfile=/tmp/go-build3929737176/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true -test.run=^(TestOSDFAuthRetrieval|TestAuthPathCompToWord|TestConstructAuthEntry|TestAuthPrivilegesFromWord|TestAuthPoliciesFromLine|TestPopulateAuthLinesMapForOrigin|TestPopulateAuthLinesMapForCache|TestSerializeAuthline|TestGetSortedSerializedAuthLines|T o@v1.45.25/priva-ifaceassert ux_amd64/vet -errorsas -ifaceassert -nilfunc ux_amd64/vet -c 1.67.3/internal/-errorsas 1.67.3/internal/-ifaceassert ux_amd64/vet x64/src/runtime/as gner/v4 ndor/bin/as ux_amd64/vet(dns block)/tmp/go-build2339574086/b001/xrootd.test /tmp/go-build2339574086/b001/xrootd.test -test.testlogfile=/tmp/go-build2339574086/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true -test.run=TestOSDFAuthRetrieval ux_amd64/compile-ifaceassert ux_amd64/vet x64/src/runtime/as hentication-libr--64 ache/go/1.24.12/-o ux_amd64/vet e oneg@v0.0.0-20191010083416-a7dc8-errorsas om/alecthomas/units@v0.0.0-20211-ifaceassert ux_amd64/vet x64/src/hash/crcas /scrape ache/go/1.24.12/-o ux_amd64/vet(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt