@@ -28,15 +28,23 @@ type McpCommand struct {
2828}
2929
3030func establishPipeToFile (dst io.WriteCloser , src io.Reader ) {
31- defer dst .Close ()
31+ defer func () {
32+ if err := dst .Close (); err != nil {
33+ log .Error (fmt .Sprintf ("Error closing pipe: %v" , err ))
34+ }
35+ }()
3236 _ , err := io .Copy (dst , src )
3337 if err != nil {
3438 log .Error ("Error establishing pipe" )
3539 }
3640}
3741
3842func establishPipeFromFile (dst io.Writer , src io.ReadCloser ) {
39- defer src .Close ()
43+ defer func () {
44+ if err := src .Close (); err != nil {
45+ log .Error (fmt .Sprintf ("Error closing pipe: %v" , err ))
46+ }
47+ }()
4048 _ , err := io .Copy (dst , src )
4149 if err != nil {
4250 log .Error ("Error establishing pipe" )
@@ -59,21 +67,33 @@ func RunAmMcpWithPipes(env map[string]string, cmd string, input_pipe io.Reader,
5967 log .Error (fmt .Sprintf ("Error creating MCPService stdin pipe: %v" , _error ))
6068 return _error
6169 }
62- defer stdin .Close ()
70+ defer func () {
71+ if err := stdin .Close (); err != nil {
72+ log .Error (fmt .Sprintf ("Error closing stdin pipe: %v" , err ))
73+ }
74+ }()
6375
6476 stdout , _error := command .StdoutPipe ()
6577 if _error != nil {
6678 log .Error (fmt .Sprintf ("Error creating MCPService stdout pipe: %v" , _error ))
6779 return _error
6880 }
69- defer stdout .Close ()
81+ defer func () {
82+ if err := stdout .Close (); err != nil {
83+ log .Error (fmt .Sprintf ("Error closing stdout pipe: %v" , err ))
84+ }
85+ }()
7086
7187 stderr , _error := command .StderrPipe ()
7288 if _error != nil {
7389 log .Error (fmt .Sprintf ("Error creating MCPService stderr pipe: %v" , _error ))
7490 return _error
7591 }
76- defer stderr .Close ()
92+ defer func () {
93+ if err := stderr .Close (); err != nil {
94+ log .Error (fmt .Sprintf ("Error closing stderr pipe: %v" , err ))
95+ }
96+ }()
7797
7898 go establishPipeToFile (stdin , input_pipe )
7999 go establishPipeFromFile (error_pipe , stderr )
0 commit comments