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

Replace the impl of Syscall.rename and remove Mono.Posix.NETStandard #1641

Merged
merged 1 commit into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
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
12 changes: 7 additions & 5 deletions src/WebJobs.Extensions.DurableTask/LinuxAppServiceFileLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;

#if !FUNCTIONS_V1
using Mono.Unix.Native;
#endif

namespace Microsoft.Azure.WebJobs.Extensions.DurableTask
{
/// <summary>
Expand Down Expand Up @@ -173,9 +170,14 @@ private void RollFiles()
// Rename current file to older file.

#if !FUNCTIONS_V1
Syscall.rename(this.logFilePath, this.archiveFilePath);
rename(this.logFilePath, this.archiveFilePath);
#endif

}

#if !FUNCTIONS_V1
[DllImport("libc", SetLastError = true)]
Copy link
Contributor

Choose a reason for hiding this comment

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

How does [DllImport] work if the library is not available (for instance, on Windows)?

Does this dynamically try to import this functionality when rename is actually called? In that case, this likely isn't an issue since this logger should never actually be used on Windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My understanding is that DllImport will not actually seek to invoke any system-level libraries until rename is called, so this shouldn't be an issue.

From this SO answer: https://stackoverflow.com/questions/39144458/what-happens-if-i-have-dllimport-c-net-for-an-api-not-supported-by-the-opera

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case, we should decide on whether in the degenerate case this logger class is used on a non-Linux platform if we fail fast with an exception, or we should wrap the call to rename() in a try-catch.

@cgillum, what are your thoughts in this scenario? I normally lean towards just letting the exception propagate, but since this is logging code I'm never quite sure of proper error handling.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I +1 failing fast if we're somehow using the logger in windows

Copy link
Member

Choose a reason for hiding this comment

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

Don't we have code that always ensures we're only running this logger in Linux? I'm fine with letting it fail on Windows, though I recommend we log the failure before rethrowing any exception so that someone debugging will have a bit more context.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So the suggestion is to: catch, then log, then re-throw? Got it :)

ConnorMcMahon marked this conversation as resolved.
Show resolved Hide resolved
private static extern int rename(string oldPath, string newPath);
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
<PackageReference Include="Microsoft.Extensions.Http" Version="2.2.0" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.12.2" />
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.12.2" />
<PackageReference Include="Mono.Posix.NETStandard" Version="1.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down