fix(webdav): register chi REPORT method in init to avoid race with settings#2712
Open
SAY-5 wants to merge 1 commit intoopencloud-eu:mainfrom
Open
fix(webdav): register chi REPORT method in init to avoid race with settings#2712SAY-5 wants to merge 1 commit intoopencloud-eu:mainfrom
SAY-5 wants to merge 1 commit intoopencloud-eu:mainfrom
Conversation
chi.RegisterMethod mutates a package-global methodMap in github.com/go-chi/chi/v5 that (*node).setEndpoint also iterates during route insertion. Calling it inside webdav.NewService at service start races with route registration in concurrently-starting services such as settings, triggering a 'concurrent map iteration and map write' Go runtime panic in chi tree.go during HTTP server initialisation. Move the call to package init so it runs before any suture-supervised service goroutine is spawned. Fixes opencloud-eu#2686 Signed-off-by: Sai Asish <saiasish.cnp@gmail.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Description
Move
chi.RegisterMethod("REPORT")fromwebdav.NewServiceinto a packageinit()function so it runs before any service goroutine is spawned by thesuture supervisor.
Related Issue
Motivation and Context
Issue #2686 reports a runtime panic during settings-service HTTP server
initialisation, with the stack ending in
chi/v5.(*node).setEndpointiterating a map (
internal/runtime/maps.(*Iter).Next/internal/runtime/maps.fatal).chi.RegisterMethodmutates the package-levelmethodMapingithub.com/go-chi/chi/v5/tree.go:(*node).setEndpointreads that same global map during route insertion attree.go:359:opencloud/pkg/runtime/serviceregisters many services (webdav,settings,activitylog,auth-app, ...) under asuturesupervisorand starts them concurrently. While webdav executed
chi.RegisterMethod("REPORT")insideNewService, another service(here
settings) could be in the middle ofmux.Route(...)→Mount→InsertRoute→setEndpointand iteratingmethodMap,producing a "concurrent map iteration and map write" runtime fatal —
exactly the stack trace in the issue.
Moving the call into
init()makes registration happen during packageimport, which is sequential and well-ordered before any
suture-supervised goroutine starts.
chi.RegisterMethodis idempotent(returns early if the method is already registered), so it remains safe.
How Has This Been Tested?
go build ./...andgo vet/gofmton the affectedpackage
go build ./services/webdav/... ./services/settings/...succeeds
go test -race ./services/webdav/pkg/service/v0/...buildscleanly under the race detector
go build ./...succeedsI do not have a deterministic local reproducer for the original panic — it
was reported as an intermittent crash during container start — but the
race is straightforward to read off the chi source: a package-global map
written by
RegisterMethodand iterated bysetEndpoint.Screenshots (if appropriate):
n/a
Types of changes
Checklist: