Skip to content

fix(seaweedfs): stop the master crashing on the crowded volume map - #5308

Merged
Aleksei Sviridkin (lexfrei) merged 1 commit into
cozystack:mainfrom
mattia-eleuteri:fix/seaweedfs-volumelayout-concurrent-map
Nov 13, 2026
Merged

Aleksei Sviridkin (lexfrei) merged 1 commit into
cozystack:mainfrom
mattia-eleuteri:fix/seaweedfs-volumelayout-concurrent-map

Conversation

@mattia-eleuteri

@mattia-eleuteri mattia-eleuteri commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

What this PR does

Backports seaweedfs/seaweedfs#11216 ("topology: fix fatal concurrent map read/write on VolumeLayout.crowded", released in 4.46) as a patch on the in-tree 4.45 image, next to reader-cache-prefetch-window.diff.

In 4.45, (*VolumeLayout).SetVolumeCrowded mutates the crowded map under accessLock.RLock(), while (*VolumeLayout).GetWritableVolumeCount reads the same map under RLock() on the Assign path. Two read-lock holders, one writing and one reading the map, make the Go runtime abort the master with fatal error: concurrent map read and map write. This cannot be recovered, so the process exits and S3 requests that need an assign fail until a master is back. The fix takes the write lock in SetVolumeCrowded; every other mutation of crowded already holds it.

patches/volume-layout-crowded-lock.diff is the upstream squash commit 5d5ea18287cfbf9e274f4b78be40a0ae220cb55d (files under weed/topology/), regenerated against the 4.45 source so it applies without offset. Its content is unchanged, including the regression test TestSetVolumeCrowdedNoRaceWithGetWritableVolumeCount, which the Dockerfile's existing go test step runs on every build.

Seen in production

On a production platform running Cozystack v1.7.0 (in-tree SeaweedFS 4.45), with a dedicated S3 cluster used as the Velero backup target:

  • Since the upgrade to 4.45 on 2026-11-05, all 3 masters crash every night with exit code 2 under the backup load, between 01:00 and 03:00 UTC: 2 crashes on 2026-11-06, about 23 on 2026-11-13, 33 to 43 restarts per master over 8 days.
  • The stack is always the same:
    fatal error: concurrent map read and map write
    ...
    github.com/seaweedfs/seaweedfs/weed/topology.(*VolumeLayout).GetWritableVolumeCount(...)
        weed/topology/volume_layout.go:834
    github.com/seaweedfs/seaweedfs/weed/server.(*MasterServer).Assign(...)
        weed/server/master_grpc_server_assign.go:97
    
  • Clients see HTTP 500 InternalError from the S3 gateway, and the nightly backups end Failed or PartiallyFailed (4 Failed and 3 PartiallyFailed on the night of 2026-11-12 to 13).

Upstream issue: seaweedfs/seaweedfs#11211.

Testing

  • git apply --check of both patches against the 4.45 source archive (SOURCE_SHA256 in the Dockerfile matches).
  • Regression test on 4.45 with only the test applied, CGO_ENABLED=0 as in the image build: fatal error: concurrent map writes, FAIL. With the fix: go test ./weed/topology/ passes, and the new test passes under -race too.
  • docker buildx build images/seaweedfs --platform linux/amd64 builds, running the patched packages' tests.
  • make test in packages/system/seaweedfs: 107 helm unit tests, the naming-guard check and the image/chart version check pass.

Lifecycle

The patch is dropped once the vendored chart reaches 4.46 or later, for example with #4879 (4.48 bump). From that release on it no longer applies, and make update-image fails until it is removed, as the Dockerfile header says. This PR is kept small so that it does not wait for #4879.

Backport

This is a fix with no CRD, migration or API change, and release-1.7 carries the same images/seaweedfs/ as main, so the backport batch should take it onto release-1.7 with a clean cherry-pick for the next v1.7.x. Clusters on v1.7 are the ones that crash today.

Downstream repositories

The diff touches only packages/system/seaweedfs/images/seaweedfs/ (a Go patch and a Dockerfile comment): no package added or renamed, no values, schema, CRD, hack/ or installer change, so no entry of the trigger map applies.

Release note

fix(seaweedfs): stop SeaweedFS masters crashing with "concurrent map read and map write" under write load, which made S3 answer 500 (backport of seaweedfs/seaweedfs#11216 onto 4.45).

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability when updating crowded-volume state concurrently with writable-volume queries.
  • Documentation
    • Added notes about the upstream fix and when the local patch can be removed.

SeaweedFS 4.45 updates the crowded-volume map of a volume layout under
the read lock, while Assign reads that map under the same read lock to
count writable volumes. Under a steady write load the Go runtime aborts
the master with "concurrent map read and map write", a fatal error that
recover cannot catch, and the S3 gateway answers 500 until a master is
elected again. Taking the write lock for the update, as every other
mutation of the map already does, removes the race.

Upstream fixed it in seaweedfs/seaweedfs#11216, released in 4.46. The
patch carries that change and its regression test unchanged, so the
build runs the test and the patch stops applying, and is dropped, once
the vendored release carries the fix.

Signed-off-by: Mattia Eleuteri <[email protected]>
Assisted-by: LLM
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The SeaweedFS patch adds a concurrent-call test and changes SetVolumeCrowded to use an exclusive lock. Dockerfile comments describe the patch, the reported upstream failure, and when to remove the patch.

Changes: Crowded-map locking

Layer / File(s) Summary
Lock behavior and concurrency test
packages/system/seaweedfs/images/seaweedfs/patches/volume-layout-crowded-lock.diff, packages/system/seaweedfs/images/seaweedfs/Dockerfile
The patch adds a test that runs SetVolumeCrowded and GetWritableVolumeCount concurrently, then changes SetVolumeCrowded to use an exclusive lock. Dockerfile comments document the patch and state when to remove it.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: Minimal · up to 9e861

This change fixes a reported SeaweedFS master crash caused by concurrent access to the crowded volume map. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: a fix in the SeaweedFS package that stops the master from crashing on the crowded volume map. The changeset matches this. The Dockerfile comments and the patch add a r…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: a fix in the SeaweedFS package that stops the master from crashing on the crowded volume map. The changeset matches this. The Dockerfile comments and the patch add a regression test and change SetVolumeCrowded from a read lock to a write lock while it updates the crowded map. The objectives confirm the same backport of upstream PR #11216.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 0f16954 and 9e861c1.

Files selected for processing: 2

  • packages/system/seaweedfs/images/seaweedfs/Dockerfile
  • packages/system/seaweedfs/images/seaweedfs/patches/volume-layout-crowded-lock.diff

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

@github-actions github-actions Bot added size/M This PR changes 30-99 lines, ignoring generated files area/storage Issues or PRs related to storage (linstor, seaweedfs, bucket, velero, harbor) kind/bug Categorizes issue or PR as related to a bug labels Nov 13, 2026
@mattia-eleuteri
mattia-eleuteri marked this pull request as ready for review November 13, 2026 08:34

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

mattia-eleuteri LGTM, E2E is green on this head. #4879 now has to drop this patch when it bumps past 4.46.

@lexfrei
Aleksei Sviridkin (lexfrei) merged commit 30c4232 into cozystack:main Nov 13, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/storage Issues or PRs related to storage (linstor, seaweedfs, bucket, velero, harbor) kind/bug Categorizes issue or PR as related to a bug size/M This PR changes 30-99 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants