Skip to content

Commit 682b7c7

Browse files
Deadlock on application exit when an error occurs in case of asynchronous Program.main()
1 parent 5e1603b commit 682b7c7

File tree

4 files changed

+78
-9
lines changed

4 files changed

+78
-9
lines changed

.github/workflows/main.yml

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
name: CSharpInteractive check
1+
name: CSharpInteractive build
22

33
on: [ push, pull_request ]
44

55
jobs:
6-
build:
7-
6+
7+
ubuntu_build:
8+
89
runs-on: ubuntu-latest
910

1011
steps:
@@ -32,3 +33,63 @@ jobs:
3233

3334
- name: Build
3435
run: dotnet run --project ./Build
36+
37+
mac_build:
38+
39+
runs-on: macos-latest
40+
41+
steps:
42+
- uses: actions/checkout@v4
43+
44+
- name: Setup .NET 6
45+
uses: actions/setup-dotnet@v3
46+
with:
47+
dotnet-version: '6.0.x'
48+
49+
- name: Setup .NET 7
50+
uses: actions/setup-dotnet@v3
51+
with:
52+
dotnet-version: '7.0.x'
53+
54+
- name: Setup .NET 8
55+
uses: actions/setup-dotnet@v3
56+
with:
57+
dotnet-version: '8.0.x'
58+
59+
- name: Setup .NET 9
60+
uses: actions/setup-dotnet@v3
61+
with:
62+
dotnet-version: '9.0.x'
63+
64+
- name: Build
65+
run: dotnet run --project ./Build
66+
67+
windows_build:
68+
69+
runs-on: windows-latest
70+
71+
steps:
72+
- uses: actions/checkout@v4
73+
74+
- name: Setup .NET 6
75+
uses: actions/setup-dotnet@v3
76+
with:
77+
dotnet-version: '6.0.x'
78+
79+
- name: Setup .NET 7
80+
uses: actions/setup-dotnet@v3
81+
with:
82+
dotnet-version: '7.0.x'
83+
84+
- name: Setup .NET 8
85+
uses: actions/setup-dotnet@v3
86+
with:
87+
dotnet-version: '8.0.x'
88+
89+
- name: Setup .NET 9
90+
uses: actions/setup-dotnet@v3
91+
with:
92+
dotnet-version: '9.0.x'
93+
94+
- name: Build
95+
run: dotnet run --project ./Build

CSharpInteractive.Templates/content/ConsoleApplication-CSharp/.template.config/template.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"type": "parameter",
3636
"datatype": "string",
3737
"description": "Version of CSharpInteractive that will be referenced.",
38-
"defaultValue": "$(version)",
38+
"defaultValue": "1.1.6",
3939
"replaces": "$(CSharpInteractiveVersion)"
4040
},
4141
"skipRestore": {

CSharpInteractive/Core/Environment.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,12 @@ public void Exit(int exitCode)
8686
return;
8787
}
8888

89-
WindowsNativeExit(exitCode);
90-
var exitThread = new Thread(() => System.Environment.Exit(exitCode));
89+
/*var exitThread = new Thread(() => System.Environment.Exit(exitCode));
9190
exitThread.Start();
9291
if (exitThread.Join(100))
9392
{
9493
return;
95-
}
94+
}*/
9695

9796
NativeExit(exitCode);
9897
}
@@ -173,7 +172,7 @@ private string GetScriptDirectory()
173172
[DllImport("libSystem.dylib", EntryPoint = "exit")]
174173
private static extern void MacNativeExit(int exitCode);
175174

176-
[DllImport("libc.so", EntryPoint = "exit")]
175+
[DllImport("libc.so.6", EntryPoint = "exit")]
177176
private static extern void LinuxNativeExit(int exitCode);
178177

179178
private static void NativeExit(int exitCode)
@@ -192,7 +191,15 @@ private static void NativeExit(int exitCode)
192191
break;
193192

194193
case PlatformID.Unix:
195-
LinuxNativeExit(exitCode);
194+
try
195+
{
196+
LinuxNativeExit(exitCode);
197+
}
198+
catch (DllNotFoundException)
199+
{
200+
MacNativeExit(exitCode);
201+
}
202+
196203
break;
197204

198205
case PlatformID.MacOSX:

TestBuild/TestBuild.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<TargetFramework>net9.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
8+
<IsPackable>false</IsPackable>
89
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
910
</PropertyGroup>
1011

0 commit comments

Comments
 (0)