Skip to content

Commit 96a0067

Browse files
committed
2 parents 280de3f + d4c588b commit 96a0067

File tree

3 files changed

+105
-3
lines changed

3 files changed

+105
-3
lines changed

.github/workflows/codeql.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
branches: [ "main", "validation/**" ]
6+
pull_request:
7+
branches: [ "main", "validation/**" ]
8+
schedule:
9+
- cron: '23 9 * * 6'
10+
11+
jobs:
12+
analyze:
13+
if: github.event.repository.fork == false
14+
name: Analyze (${{ matrix.language }})
15+
# Runner size impacts CodeQL analysis time. To learn more, please see:
16+
# - https://gh.io/recommended-hardware-resources-for-running-codeql
17+
# - https://gh.io/supported-runners-and-hardware-resources
18+
# - https://gh.io/using-larger-runners (GitHub.com only)
19+
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
20+
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
21+
permissions:
22+
# required for all workflows
23+
security-events: write
24+
25+
# required to fetch internal or private CodeQL packs
26+
packages: read
27+
28+
# only required for workflows in private repositories
29+
actions: read
30+
contents: read
31+
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
include:
36+
- language: actions
37+
build-mode: none
38+
- language: csharp
39+
build-mode: none
40+
# CodeQL supports the following values keywords for 'language': 'actions', 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'rust', 'swift'
41+
# Use `c-cpp` to analyze code written in C, C++ or both
42+
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
43+
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
44+
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
45+
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
46+
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
47+
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
48+
steps:
49+
- name: Checkout repository
50+
uses: actions/checkout@v4
51+
52+
# Add any setup steps before running the `github/codeql-action/init` action.
53+
# This includes steps like installing compilers or runtimes (`actions/setup-node`
54+
# or others). This is typically only required for manual builds.
55+
# - name: Setup runtime (example)
56+
# uses: actions/setup-example@v1
57+
58+
# Initializes the CodeQL tools for scanning.
59+
- name: Initialize CodeQL
60+
uses: github/codeql-action/init@v4
61+
with:
62+
languages: ${{ matrix.language }}
63+
build-mode: ${{ matrix.build-mode }}
64+
# If you wish to specify custom queries, you can do so here or in a config file.
65+
# By default, queries listed here will override any specified in a config file.
66+
# Prefix the list here with "+" to use these queries and those in the config file.
67+
68+
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
69+
# queries: security-extended,security-and-quality
70+
71+
# If the analyze step fails for one of the languages you are analyzing with
72+
# "We were unable to automatically build your code", modify the matrix above
73+
# to set the build mode to "manual" for that language. Then modify this step
74+
# to build your code.
75+
# ℹ️ Command-line programs to run using the OS shell.
76+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
77+
- name: Run manual build steps
78+
if: matrix.build-mode == 'manual'
79+
shell: bash
80+
run: |
81+
echo 'If you are using a "manual" build mode for one or more of the' \
82+
'languages you are analyzing, replace this with the commands to build' \
83+
'your code, for example:'
84+
echo ' make bootstrap'
85+
echo ' make release'
86+
exit 1
87+
88+
- name: Perform CodeQL Analysis
89+
uses: github/codeql-action/analyze@v4
90+
with:
91+
category: "/language:${{matrix.language}}"

src/ModelContextProtocol.Core/Client/StdioClientSessionTransport.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,14 @@ protected override async ValueTask CleanupAsync(Exception? error = null, Cancell
107107
using var timeoutCts = new CancellationTokenSource(_options.ShutdownTimeout);
108108
await _process.WaitForExitAsync(timeoutCts.Token).ConfigureAwait(false);
109109
#else
110-
_process.WaitForExit((int)_options.ShutdownTimeout.TotalMilliseconds);
110+
// WaitForExit(int) does not guarantee all ErrorDataReceived events have been
111+
// dispatched. The parameterless WaitForExit() does, so call it after the timed
112+
// wait confirms the process exited. Since the process is already dead, the
113+
// parameterless overload returns almost immediately—it just drains the event queue.
114+
if (_process.WaitForExit((int)_options.ShutdownTimeout.TotalMilliseconds))
115+
{
116+
_process.WaitForExit();
117+
}
111118
#endif
112119
}
113120
catch { }

tests/ModelContextProtocol.AspNetCore.Tests/MapMcpTests.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using ModelContextProtocol.Client;
66
using ModelContextProtocol.Protocol;
77
using ModelContextProtocol.Server;
8+
using ModelContextProtocol.Tests.Utils;
89
using System.ComponentModel;
910
using System.Diagnostics;
1011
using System.Net;
@@ -443,8 +444,11 @@ public async Task OutgoingFilter_MultipleFilters_ExecuteInOrder()
443444

444445
// The outermost filter's "after" callback runs after the response has been
445446
// sent to the client, so ListToolsAsync may return before it executes.
446-
// Wait for it to complete before asserting.
447-
await allFiltersComplete.Task.WaitAsync(TestContext.Current.CancellationToken);
447+
// Wait for it to complete before asserting, but use a timeout to avoid hanging
448+
// the test indefinitely if the filter pipeline regresses.
449+
using var allFiltersCts = CancellationTokenSource.CreateLinkedTokenSource(TestContext.Current.CancellationToken);
450+
allFiltersCts.CancelAfter(TestConstants.DefaultTimeout);
451+
await allFiltersComplete.Task.WaitAsync(allFiltersCts.Token);
448452

449453
Assert.Equal(["filter1-before", "filter2-before", "filter2-after", "filter1-after"], executionOrder);
450454
}

0 commit comments

Comments
 (0)