Skip to content

Commit

Permalink
add missing dispose for process instances
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Sep 10, 2024
1 parent 1ee6449 commit cbeffaf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/DotNetWorker.Core/StartupHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public static void Initialize()
#if NET5_0_OR_GREATER
int processId = Environment.ProcessId;
#else
int processId = Process.GetCurrentProcess().Id;
using var process = Process.GetCurrentProcess();
int processId = process.Id;
#endif

static bool WaitOnDebugger(int cycle)
Expand Down
9 changes: 8 additions & 1 deletion src/DotNetWorker.Core/WorkerInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ internal sealed class WorkerInformation

public string RuntimeIdentifier => RuntimeInformation.RuntimeIdentifier;
#else
public int ProcessId => Process.GetCurrentProcess().Id;
public int ProcessId
{
get
{
using var process = Process.GetCurrentProcess();
return process.Id;
}
}

public string RuntimeIdentifier => "n/a"; // Resolve in netstandard
#endif
Expand Down
3 changes: 2 additions & 1 deletion src/DotNetWorker.OpenTelemetry/FunctionsResourceDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public Resource Detect()
attributeList.Add(new KeyValuePair<string, object>(ResourceSemanticConventions.ServiceVersion, version));
attributeList.Add(new KeyValuePair<string, object>(ResourceSemanticConventions.AISDKPrefix,
$@"{OpenTelemetryConstants.SDKPrefix}:{typeof(FunctionsResourceDetector).Assembly.GetName().Version}"));
attributeList.Add(new KeyValuePair<string, object>(ResourceSemanticConventions.ProcessId, Process.GetCurrentProcess().Id));
using var process = Process.GetCurrentProcess();
attributeList.Add(new KeyValuePair<string, object>(ResourceSemanticConventions.ProcessId, process.Id));

// Add these attributes only if running in Azure.
if (!string.IsNullOrEmpty(serviceName))
Expand Down

0 comments on commit cbeffaf

Please sign in to comment.