Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Add native error codes and messages to managed SNI Named Pipe disconnect errors, so as to match native SNI behavior. - #19135

Merged
corivera merged 2 commits into
dotnet:masterfrom
corivera:AddNativeNPErrors
May 1, 2017
Merged

Add native error codes and messages to managed SNI Named Pipe disconnect errors, so as to match native SNI behavior.#19135
corivera merged 2 commits into
dotnet:masterfrom
corivera:AddNativeNPErrors

Conversation

@corivera

@corivera corivera commented Apr 29, 2017

Copy link
Copy Markdown
Member

Resolves some of the issues seen in https://github.com/dotnet/corefx/issues/19057


if (packet.Length == 0)
{
return ReportErrorAndReleasePacket(packet, 0, SNICommon.ConnTerminatedError, string.Empty);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

should you update the identical code in SNITcpHandle.cs?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@corivera Is this mechanism needed for SNITcpHandle?

return Interop.Kernel32.GetMessage(error);
}
}
}

@stephentoub stephentoub Apr 30, 2017

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You shouldn't need these P/Invokes... you can just do:

string message = new Win32Exception(error).Message;

Presumably this only happens on error paths where the extra allocation for the exception object won't matter. Win32Exception itself calls either StrError or GetMessage:
https://github.com/dotnet/corefx/blob/master/src/Microsoft.Win32.Primitives/src/System/ComponentModel/Win32Exception.Unix.cs#L9
https://github.com/dotnet/corefx/blob/master/src/Microsoft.Win32.Primitives/src/System/ComponentModel/Win32Exception.Windows.cs#L9
Win32Exception's parameterless ctor also calls Marshal.GetLastWin32Error, so you could skip calling that manually below, too, if you wanted to:

var e = new Win32Exception();
ReportErrorAndReleasePacket(packet, (uint)e.NativeErrorCode, 0, e.Message);

…t errors, so as to match native SNI behavior.
@corivera

corivera commented May 1, 2017

Copy link
Copy Markdown
Member Author

Seeing some test failures with Entity Framework tests after adding these changes. Investigating.

Edit: Forgot to add return statements for the error codes. Fixed.

{
return ReportErrorAndReleasePacket(packet, 0, SNICommon.ConnTerminatedError, string.Empty);
var e = new Win32Exception();
return ReportErrorAndReleasePacket(packet, (uint)e.NativeErrorCode, 0, e.Message);

@saurabh500 saurabh500 May 1, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This may not matter for NP on Linux, but how does Win32Exception work on Linux? For the sake of correctness, do we need to have a platform specific file which references Win32Exception on Windows and something else on Linux?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Using Win32Exception avoids platform specific files. It has its own versioning for handling error messages and error codes

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I also added native error checking for connection terminated errors in TCP handle, for consistency.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ahh. Didn't scroll through completely before commenting.


if (packet.Length == 0)
{
return ReportErrorAndReleasePacket(packet, 0, SNICommon.ConnTerminatedError, string.Empty);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@corivera Is this mechanism needed for SNITcpHandle?

@corivera
corivera merged commit 608985c into dotnet:master May 1, 2017
@corivera
corivera deleted the AddNativeNPErrors branch May 1, 2017 21:58
@karelz karelz modified the milestone: 2.0.0 May 5, 2017
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.

6 participants