mcp: fix goroutine leaks in unit tests (#496)
This PR fixes goroutine leaks in all unit tests. To find the leaks I integrated https://github.com/uber-go/goleak and I suggest to keep using it to catch any future regressions. I used the folowing script to more easily find individual tests which were leaking goroutines: ``` for t in $(go test -run=Nothing -list=. ./mcp | grep -v ok); do go test ./mcp -run="$t" > /dev/null && echo -n . || echo -e "\nDetected leak: $t"; done ```
This commit is contained in:
parent
14e776db6f
commit
010bdbc64d
1 changed files with 72 additions and 54 deletions
|
|
@ -18,6 +18,7 @@ import (
|
|||
|
||||
// !+streamablehandler
|
||||
|
||||
// TODO: Until we have a way to clean up abandoned sessions, this test will leak goroutines (see #499)
|
||||
func ExampleStreamableHTTPHandler() {
|
||||
// Create a new streamable handler, using the same MCP server for every request.
|
||||
//
|
||||
|
|
@ -45,7 +46,7 @@ func ExampleStreamableHTTPHandler_middleware() {
|
|||
server := mcp.NewServer(&mcp.Implementation{Name: "server", Version: "v0.1.0"}, nil)
|
||||
handler := mcp.NewStreamableHTTPHandler(func(r *http.Request) *mcp.Server {
|
||||
return server
|
||||
}, nil)
|
||||
}, &mcp.StreamableHTTPOptions{Stateless: true})
|
||||
loggingHandler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
// Example debugging; you could also capture the response.
|
||||
body, err := io.ReadAll(req.Body)
|
||||
|
|
|
|||
Loading…
Reference in a new issue