File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
mcp-core/src/main/java/io/modelcontextprotocol/spec Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change 77import java .time .Duration ;
88import java .util .Map ;
99import java .util .concurrent .ConcurrentHashMap ;
10+ import java .util .concurrent .atomic .AtomicBoolean ;
1011import java .util .concurrent .atomic .AtomicInteger ;
1112import java .util .concurrent .atomic .AtomicLong ;
1213import java .util .concurrent .atomic .AtomicReference ;
@@ -65,6 +66,8 @@ public class McpServerSession implements McpLoggableSession {
6566
6667 private volatile McpSchema .LoggingLevel minLoggingLevel = McpSchema .LoggingLevel .INFO ;
6768
69+ private volatile AtomicBoolean closed = new AtomicBoolean (false );
70+
6871 /**
6972 * Creates a new server session with the given parameters and the transport to use.
7073 * @param id session id
@@ -346,13 +349,20 @@ private MethodNotFoundError getMethodNotFoundError(String method) {
346349 @ Override
347350 public Mono <Void > closeGracefully () {
348351 // TODO: clear pendingResponses and emit errors?
349- return this .transport .closeGracefully ();
352+ if (this .closed .compareAndSet (false , true )) {
353+ return this .transport .closeGracefully ();
354+ }
355+ else {
356+ return Mono .empty ();
357+ }
350358 }
351359
352360 @ Override
353361 public void close () {
354362 // TODO: clear pendingResponses and emit errors?
355- this .transport .close ();
363+ if (this .closed .compareAndSet (false , true )) {
364+ this .transport .close ();
365+ }
356366 }
357367
358368 /**
You can’t perform that action at this time.
0 commit comments