Pomelo.EntityFrameworkCore.MySql
Pomelo.EntityFrameworkCore.MySql copied to clipboard
[Bug] pipe name wrongly created on Windows, preventing access to any database
Steps to reproduce
Try to access any Mysql/Mariadb database on Windows with named pipes with Pomelo. You will get an exception.
The issue
OpenNamedPipeAsync in ServerSession.cs wrongly creates a pipe name with format (host)\pipe(pineName) with these lines:
// see https://docs.microsoft.com/en-us/windows/win32/ipc/pipe-names for pipe name format
var pipeName = @"\\" + cs.HostNames![0] + @"\pipe\" + cs.PipeName;
[...]
var namedPipeStream = new NamedPipeClientStream(cs.HostNames![0], cs.PipeName, PipeDirection.InOut, PipeOptions.Asynchronous);
But NamedPipeClientStream actually does the same thing internally, leading to a wrong pipename. Proof:
string pipHost = ".";
// TimeoutException
pipName = @"\\.\pipe\MySQL";
using var pipe = new System.IO.Pipes.NamedPipeClientStream(pipHost, pipName, System.IO.Pipes.PipeDirection.InOut, System.IO.Pipes.PipeOptions.Asynchronous);
pipe.Connect(2_000);
// Connect immediately
pipName = "MySQL";
using var pipe = new System.IO.Pipes.NamedPipeClientStream(pipHost, pipName, System.IO.Pipes.PipeDirection.InOut, System.IO.Pipes.PipeOptions.Asynchronous);
pipe.Connect(2_000);
The solution is simply to change the line:
var pipeName = @"\\" + cs.HostNames![0] + @"\pipe\" + cs.PipeName;
into
var pipeName = cs.PipeName;
Further technical details
MySQL version: Operating system: Windows Pomelo.EntityFrameworkCore.MySql version: 7.0.0 Microsoft.AspNetCore.App version: 6.0.x