Skip to content

Commit 3672866

Browse files
committed
chore: safely converts an exception to string without accessing StackTrace
1 parent 5eede25 commit 3672866

File tree

2 files changed

+10
-37
lines changed

2 files changed

+10
-37
lines changed

src/AElf.Runtime.CSharp/Executive.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,23 @@ namespace AElf.Runtime.CSharp;
2222
public class Executive : IExecutive
2323
{
2424
/// <summary>
25-
/// Safely converts an exception to string, handling cases where ToString() might fail
26-
/// (e.g., during StackOverflowException when getting StackTrace causes another overflow)
25+
/// Safely converts an exception to string without accessing StackTrace.
26+
/// IMPORTANT: Do NOT call ex.ToString() as it accesses StackTrace property,
27+
/// which can trigger StackOverflowException when the stack is nearly exhausted.
28+
/// StackOverflowException cannot be caught by try-catch in .NET.
2729
/// </summary>
2830
private static string SafeExceptionToString(Exception ex)
2931
{
32+
// Keep this method as simple as possible to minimize stack usage
33+
// when the stack is nearly exhausted
3034
try
3135
{
32-
return ex.ToString();
36+
// Only use GetType() and Message - these don't access StackTrace
37+
return string.Concat(ex.GetType().FullName, ": ", ex.Message);
3338
}
3439
catch
3540
{
36-
// Fallback to simple message if ToString() fails (e.g., during stack overflow)
37-
try
38-
{
39-
return $"{ex.GetType().Name}: {ex.Message}";
40-
}
41-
catch
42-
{
43-
return "Exception occurred (unable to retrieve details)";
44-
}
41+
return "Exception occurred";
4542
}
4643
}
4744

templates/build-template-linux.yml

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,8 @@ jobs:
2121
- script: |
2222
echo "=== Disk space before cleanup ==="
2323
df -h /
24-
# Remove unnecessary pre-installed software to free disk space
25-
sudo rm -rf /usr/share/dotnet/shared/Microsoft.AspNetCore.App/6.* || true
26-
df -h /
27-
sudo rm -rf /usr/share/dotnet/shared/Microsoft.AspNetCore.App/7.* || true
28-
df -h /
29-
sudo rm -rf /usr/share/dotnet/shared/Microsoft.NETCore.App/6.* || true
30-
df -h /
31-
sudo rm -rf /usr/share/dotnet/shared/Microsoft.NETCore.App/7.* || true
32-
df -h /
24+
# Remove pre-installed android sdk to free disk space
3325
sudo rm -rf /usr/local/lib/android || true
34-
df -h /
35-
sudo rm -rf /opt/ghc || true
36-
df -h /
37-
sudo rm -rf /usr/share/swift || true
38-
df -h /
39-
sudo rm -rf /usr/local/share/powershell || true
40-
df -h /
41-
sudo rm -rf /usr/local/share/chromium || true
42-
df -h /
43-
sudo rm -rf /usr/local/.ghcup || true
44-
df -h /
45-
# Clean apt cache
46-
sudo apt-get clean || true
47-
df -h /
48-
# Clean Docker images
49-
docker system prune -af || true
5026
echo "=== Disk space after cleanup ==="
5127
df -h /
5228
displayName: 'Free disk space'

0 commit comments

Comments
 (0)