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

Don't unload MsQuic from the process #75441

Merged
merged 3 commits into from
Sep 13, 2022
Merged

Conversation

rzikm
Copy link
Member

@rzikm rzikm commented Sep 12, 2022

Since MsQuic library loads libmsquic.lttng.so on Linuxes it is weird to unload just the library and not the dependent libraries as well, and since we cannot touch libmsquic.lttng.so from .NET, it seems better to keep libmsquic loaded in memory to prevent any weird behavior by having the library only partially loaded.

Note that this change does not negate the benefit of #74749, the threads are still being stopped and deallocated in the MsQuicClose call.

Related:

Fixes #74629

cc: @stephentoub, @jkotas

@ghost
Copy link

ghost commented Sep 12, 2022

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

Since MsQuic library loads libmsquic.lttng.so on Linuxes it is weird to unload just the library and not the dependent libraries as well, and since we cannot touch libmsquic.lttng.so from .NET, it seems better to keep libmsquic loaded in memory to prevent any weird behavior by having the library only partially loaded.

Related:

cc: @stepehtoub, @jkotas

Author: rzikm
Assignees: -
Labels:

area-System.Net.Quic

Milestone: -

@rzikm rzikm requested a review from a team September 12, 2022 09:07
Copy link
Member

@ManickaP ManickaP left a comment

Choose a reason for hiding this comment

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

LGTM, small comment to consider.

private static bool TryLoadMsQuic(out IntPtr msQuicHandle) =>
NativeLibrary.TryLoad($"{Interop.Libraries.MsQuic}.{MsQuicVersion.Major}", typeof(MsQuicApi).Assembly, DllImportSearchPath.AssemblyDirectory, out msQuicHandle) ||
NativeLibrary.TryLoad(Interop.Libraries.MsQuic, typeof(MsQuicApi).Assembly, DllImportSearchPath.AssemblyDirectory, out msQuicHandle);
private static IntPtr TryLoadMsQuic() =>
Copy link
Member

Choose a reason for hiding this comment

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

Should this still be named Try...? Since it doesn't return bool and out IntPtr anymore.

@@ -20,6 +20,8 @@ internal sealed unsafe partial class MsQuicApi

private static readonly Version MsQuicVersion = new Version(2, 1);

private static readonly IntPtr MsQuicHandle = TryLoadMsQuic();
Copy link
Member

Choose a reason for hiding this comment

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

If we were to keep the original shape of TryLoadMsQuic, this could be done as: TryLoadMsQuic(out IntPtr handle) ? handle : IntPtr.Zero

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm, that could work, I originally wanted to set it from the static ctor using the old signature and compiler complained with Initialize all static fields in 'MsQuicApi' when those fields are declared and remove the explicit static constructor

apiTable = null;
if (!NativeLibrary.TryGetExport(msQuicHandle, "MsQuicOpenVersion", out IntPtr msQuicOpenVersionAddress))
if (!NativeLibrary.TryGetExport(MsQuicHandle, "MsQuicOpenVersion", out IntPtr msQuicOpenVersionAddress))
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be NativeLibrary.GetExport.

The failures to get exports from the MsQuic library should be fatal. If we fail to get the export, it means that there is something very wrong.

@karelz karelz added this to the 8.0.0 milestone Sep 12, 2022
Comment on lines 65 to 69
if (MsQuicHandle == IntPtr.Zero)
{
// MsQuic library not loaded
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (MsQuicHandle == IntPtr.Zero)
{
// MsQuic library not loaded
return;
}
if (!TryLoadMsQuic(out MsQuicHandle))
{
// MsQuic library not loaded
return;
}

and delete inline initialization of MsQuicHandle above

Copy link
Member

Choose a reason for hiding this comment

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

Instead of storing MsQuicHandle, you can consider storing the pointers to the two exports in statics instead. It would save a bit of redundant work on the re-initialization.

@@ -185,9 +176,11 @@ private static bool TryOpenMsQuic(IntPtr msQuicHandle, out QUIC_API_TABLE* apiTa
return true;
}

private static bool TryCloseMsQuic(IntPtr msQuicHandle, QUIC_API_TABLE* apiTable)
private static bool TryCloseMsQuic(QUIC_API_TABLE* apiTable)
Copy link
Member

Choose a reason for hiding this comment

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

This can return void if you incorporate my other feedback

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

LGTM

@jkotas jkotas merged commit 6214022 into dotnet:main Sep 13, 2022
rzikm added a commit to rzikm/dotnet-runtime that referenced this pull request Sep 13, 2022
carlossanlop pushed a commit that referenced this pull request Sep 23, 2022
…sources (#75163, #75441) (#75521)

* Unload MsQuic after checking for QUIC support to free resources (#75163)

* Revert "Revert "Unload MsQuic after checking for QUIC support to free resources. (#74749)" (#74984)"

This reverts commit 953f524.

* update helix images

* update helix images

* Improve diagnostics when opening MsQuic

Co-authored-by: Radek Zikmund <radekzikmund@microsoft.com>

* Don't unload MsQuic from the process (#75441)

* Revert helix queues change (to be done in another PR)

* Code review feedback
@ghost ghost locked as resolved and limited conversation to collaborators Oct 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HttpClient creates Quic threads even if HTTP/3 is not in use
4 participants