Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix external profilers crashing when starting the server #5642

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Robust.Shared/Utility/FileHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
using TerraFX.Interop.Windows;
Expand All @@ -9,6 +11,9 @@ namespace Robust.Shared.Utility;

internal static class FileHelper
{
// Scanning modules is expensive and profilers don't magically appear mid execution
private static bool? _isUnderProfiler;

/// <summary>
/// Try to open a file for reading. If the file does not exist, the operation fails without exception.
/// </summary>
Expand Down Expand Up @@ -44,6 +49,21 @@ private static unsafe bool TryGetFileWindows(string path, [NotNullWhen(true)] ou
return false;
}

// When using external profilers like dotTrace in line-by-line mode, this shit breaks
// So we have to do the slow File.Exists() check in those cases because what else can we do?
_isUnderProfiler ??= Process.GetCurrentProcess()
.Modules
.Cast<ProcessModule>()
.Any(m => m.ModuleName.Contains("JetBrains") ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't hardcode these.

m.ModuleName.Contains("dotTrace") ||
m.ModuleName.Contains("profiler", StringComparison.OrdinalIgnoreCase));

if (_isUnderProfiler.Value && !File.Exists(path))
{
stream = null;
return false;
}

try
{
HANDLE file;
Expand Down
Loading