-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Unnecesary use of GCHandle in Windows Socket code #86513
Comments
Tagging subscribers to this area: @dotnet/ncl Issue DetailsThis was reported by customer that application can crash with OoMs because memory can become highly fragmented because of small chunks of pinned memory. That generally points to socketAddress in At the moment we hold the For ConnextEx and WSASendTo the socket address is documented as The WSAReceiveFrom is different as the SocketAddress is While the first part should be easy to fix (and TCP gets most use) solving the UDP receiving may take some more effort. That would also contribute to #30797.
|
This was reported by customer that application can crash with OoMs because memory can become highly fragmented because of small chunks of pinned memory. That generally points to socketAddress in
ConnectEx
. (used bySocket.ConnectAsync
)At the moment we hold the
GCHandle
even after the Connect is finished through life of the Socket. That can be fixed easily but furthermore it does not seems to be needed at all.For ConnextEx and WSASendTo the socket address is documented as
[In]
and needs to be preserved only through initial call and not through life of the overlapped IO. (confirmed with Windows networking team) We can use simplefixed
instead of allocating GCHandle and pinning the memory in heavy way.The WSAReceiveFrom is different as the SocketAddress is
out
and sockerAddressLength is[in,out]
. We may use NativeMemory for that as the current logic with caching GCHanlde may not work anyway. TheReceiveFrom
will likely receive packets from various sources (for simple duplex simpleReceive
can be used) and we will keep allocating GCHandle for (almost) every packet.While the first part should be easy to fix (and TCP gets most use) solving the UDP receiving may take some more effort. That would also contribute to #30797.
The text was updated successfully, but these errors were encountered: