Skip to content

Commit 7134686

Browse files
Fix concurrent server process resource contention bugs (and add a test to produce them) (#257)
* add stdio test to trigger contention bugs Signed-off-by: Connor Braa <[email protected]> * clean up and reorg Signed-off-by: Connor Braa <[email protected]> * modernize Signed-off-by: Connor Braa <[email protected]> * more crush config to gitignore Signed-off-by: Connor Braa <[email protected]> * stop expecting failure Signed-off-by: Connor Braa <[email protected]> * unify tests into 1 big one that will actually fail Signed-off-by: Connor Braa <[email protected]> * gr Signed-off-by: Connor Braa <[email protected]> * add fslocking to fix various concurrency bugs Signed-off-by: Connor Braa <[email protected]> * cleanup and increase lock granularity Squashed commit of the following: commit c07d03c4a905ae3716e99ee1ec49bd3af2516a86 Author: Connor Braa <[email protected]> Date: Wed Jul 30 14:05:17 2025 -0700 Updating call to match new signature commit 40a89c70b79327f2374cc127cb57bb8a9165eb09 Author: Connor Braa <[email protected]> Date: Wed Jul 30 14:05:05 2025 -0700 Updating call to match new signature commit 5a14e6ec8e96e06c2b44612cf53c18fa127ad36d Author: Connor Braa <[email protected]> Date: Wed Jul 30 14:04:52 2025 -0700 Updating call to match new signature commit 79c0fcadc7335333d798d5d2ce8f960f3e08c768 Author: Connor Braa <[email protected]> Date: Wed Jul 30 14:04:39 2025 -0700 Fixing the unparam issue by removing unused return value commit d147e125488f160d43e8d616213fffd0bdd3c9d8 Author: Connor Braa <[email protected]> Date: Wed Jul 30 14:04:07 2025 -0700 Running go fmt to fix formatting issues commit ef2c0d414b47c14f1e113e85c1f556d167fe0ac3 Author: Connor Braa <[email protected]> Date: Wed Jul 30 14:02:02 2025 -0700 Fixing the remaining lock usage in Update method commit 685d0fc718e05ab9d387aac817886ab144baa257 Author: Connor Braa <[email protected]> Date: Wed Jul 30 14:01:09 2025 -0700 Using git notes lock for state save operations commit b3b0ffb01e8f277294e6db22cd6e379dbf4c8ab1 Author: Connor Braa <[email protected]> Date: Wed Jul 30 14:00:59 2025 -0700 Using git notes lock for git notes operations commit fcb8d4134bd8947aeb9da342fc07117b8ef8e47a Author: Connor Braa <[email protected]> Date: Wed Jul 30 14:00:49 2025 -0700 Using worktree-specific lock for worktree initialization commit 706a9872042cab580bf90b296eddc4e95e8ab416 Author: Connor Braa <[email protected]> Date: Wed Jul 30 14:00:37 2025 -0700 Using git notes lock for propagation operations commit 7e5eb037a04e7bb93c5da28a8d74ad2f5b539664 Author: Connor Braa <[email protected]> Date: Wed Jul 30 14:00:21 2025 -0700 Using repository-level lock for setup operations commit f683d7a69f7db21eebfc1b2056db682ad1389645 Author: Connor Braa <[email protected]> Date: Wed Jul 30 14:00:08 2025 -0700 Updating repository initialization to use lock manager commit 7efe09e3048f10c2d388c8937f29d25c247d1b01 Author: Connor Braa <[email protected]> Date: Wed Jul 30 13:59:59 2025 -0700 Updating repository struct to use the new lock manager commit 63057d9c366d39e40ac2289a1f403f8879405afe Author: Connor Braa <[email protected]> Date: Wed Jul 30 13:59:43 2025 -0700 Implementing granular locking with different lock types to reduce contention commit 414f772ec067d5ab4b645bd0871974bc9f22dc0e Author: Connor Braa <[email protected]> Date: Wed Jul 30 13:59:00 2025 -0700 Renaming lock.go to fslock.go as requested commit 1a9b093403b207dc704e6ee67528fd58fa50ee12 Author: Connor Braa <[email protected]> Date: Wed Jul 30 13:57:37 2025 -0700 Create environment maximum-swift: Optimize filesystem locking granularity Signed-off-by: Connor Braa <[email protected]> * range int Signed-off-by: Connor Braa <[email protected]> * cleanup fslock delay calc Signed-off-by: Connor Braa <[email protected]> * switch to gofrs/flock for fslock impl: it should work on windows and is considerably more performant Signed-off-by: Connor Braa <[email protected]> * cleanup and remove extraneous locking Signed-off-by: Connor Braa <[email protected]> * remove extraneous custom lock impl Signed-off-by: Connor Braa <[email protected]> * clean up llm slop comments Signed-off-by: Connor Braa <[email protected]> * comment hash algo Co-authored-by: Dagger Assistant <[email protected]> Signed-off-by: Connor Braa <[email protected]> * bounds check cmd/container-use/stdio_test.go Co-authored-by: Dagger Assistant <[email protected]> Signed-off-by: Connor Braa <[email protected]> * raise push err in repository/git.go Co-authored-by: Dagger Assistant <[email protected]> Signed-off-by: Connor Braa <[email protected]> * utilize flock.go err helper in loadState Signed-off-by: Connor Braa <[email protected]> * log mkdirall errors and chain methods a lil Signed-off-by: Connor Braa <[email protected]> --------- Signed-off-by: Connor Braa <[email protected]> Signed-off-by: Connor Braa <[email protected]> Co-authored-by: Dagger Assistant <[email protected]>
1 parent b1c5a98 commit 7134686

File tree

8 files changed

+663
-56
lines changed

8 files changed

+663
-56
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/cu
22
/container-use
3+
/cmd/container-use/container-use
34
/container-use.exe
45
/completions/
56

@@ -24,3 +25,8 @@ build/
2425
.Trashes
2526
ehthumbs.db
2627
Thumbs.db
28+
29+
# Crush directory
30+
.crush/
31+
.crush.json
32+
CRUSH.md
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package main_test
2+
3+
import (
4+
"context"
5+
"os"
6+
"os/exec"
7+
"path/filepath"
8+
"sync"
9+
"testing"
10+
11+
"github.com/stretchr/testify/require"
12+
)
13+
14+
var (
15+
binaryPath string
16+
binaryPathOnce sync.Once
17+
)
18+
19+
// getContainerUseBinary builds the container-use binary once per test run
20+
func getContainerUseBinary(t *testing.T) string {
21+
binaryPathOnce.Do(func() {
22+
t.Log("Building fresh container-use binary...")
23+
cmd := exec.Command("go", "build", "-o", "container-use", ".")
24+
cmd.Stderr = os.Stderr
25+
cmd.Stdout = os.Stdout
26+
err := cmd.Run()
27+
if err != nil {
28+
t.Fatalf("Failed to build container-use binary: %v", err)
29+
}
30+
31+
abs, err := filepath.Abs("container-use")
32+
if err != nil {
33+
t.Fatalf("Failed to get absolute path: %v", err)
34+
}
35+
binaryPath = abs
36+
})
37+
return binaryPath
38+
}
39+
40+
// setupGitRepo initializes a git repository in the given directory
41+
func setupGitRepo(t *testing.T, repoDir string) {
42+
ctx := context.Background()
43+
44+
cmds := [][]string{
45+
{"init"},
46+
{"config", "user.email", "[email protected]"},
47+
{"config", "user.name", "Test User"},
48+
{"config", "commit.gpgsign", "false"},
49+
}
50+
51+
for _, cmd := range cmds {
52+
err := runGitCommand(ctx, repoDir, cmd...)
53+
require.NoError(t, err, "Failed to run git %v", cmd)
54+
}
55+
56+
writeFile(t, repoDir, "README.md", "# E2E Test Repository\n")
57+
writeFile(t, repoDir, "package.json", `{
58+
"name": "e2e-test-project",
59+
"version": "1.0.0",
60+
"main": "index.js"
61+
}`)
62+
63+
err := runGitCommand(ctx, repoDir, "add", ".")
64+
require.NoError(t, err, "Failed to stage files")
65+
err = runGitCommand(ctx, repoDir, "commit", "-m", "Initial commit")
66+
require.NoError(t, err, "Failed to commit")
67+
}
68+
69+
// writeFile creates a file with the given content
70+
func writeFile(t *testing.T, repoDir, path, content string) {
71+
fullPath := filepath.Join(repoDir, path)
72+
dir := filepath.Dir(fullPath)
73+
err := os.MkdirAll(dir, 0755)
74+
require.NoError(t, err, "Failed to create dir")
75+
err = os.WriteFile(fullPath, []byte(content), 0644)
76+
require.NoError(t, err, "Failed to write file")
77+
}
78+
79+
// runGitCommand runs a git command in the specified directory
80+
func runGitCommand(ctx context.Context, dir string, args ...string) error {
81+
cmd := exec.CommandContext(ctx, "git", args...)
82+
cmd.Dir = dir
83+
_, err := cmd.CombinedOutput()
84+
return err
85+
}

0 commit comments

Comments
 (0)