File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -339,9 +339,8 @@ func (ts *Toolset) tryRestart(ctx context.Context) bool {
339339
340340func (ts * Toolset ) Instructions () string {
341341 ts .mu .Lock ()
342- started := ts .started
343- ts .mu .Unlock ()
344- if ! started {
342+ defer ts .mu .Unlock ()
343+ if ! ts .started {
345344 // TODO: this should never happen...
346345 return ""
347346 }
Original file line number Diff line number Diff line change 1+ package mcp
2+
3+ import (
4+ "sync"
5+ "testing"
6+ )
7+
8+ func TestInstructions_Concurrent (t * testing.T ) {
9+ t .Parallel ()
10+
11+ ts := & Toolset {
12+ started : true ,
13+ instructions : "initial" ,
14+ }
15+
16+ var wg sync.WaitGroup
17+ for range 100 {
18+ wg .Add (2 )
19+ go func () {
20+ defer wg .Done ()
21+ // Simulate what doStart does (always called under ts.mu)
22+ ts .mu .Lock ()
23+ ts .instructions = "updated"
24+ ts .mu .Unlock ()
25+ }()
26+ go func () {
27+ defer wg .Done ()
28+ _ = ts .Instructions ()
29+ }()
30+ }
31+ wg .Wait ()
32+ }
You can’t perform that action at this time.
0 commit comments