Skip to content

Error when unix socket is used with SocketsHttpConnectionFactory #40361

@JamesNK

Description

@JamesNK

I'm trying to use the new SocketsHttpConnectionFactory with a unix socket. I'm inheriting from the factory:

public class UnixDomainSocketsConnectionFactory : SocketsHttpConnectionFactory
{
    private readonly UnixDomainSocketEndPoint _endPoint;

    public UnixDomainSocketsConnectionFactory(UnixDomainSocketEndPoint endPoint)
    {
        _endPoint = endPoint;
    }

    public override Socket CreateSocket(HttpRequestMessage message, EndPoint? endPoint, IConnectionProperties options)
    {
        return new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);
    }

    public override async ValueTask<Connection> EstablishConnectionAsync(HttpRequestMessage message, EndPoint? endPoint, IConnectionProperties options, CancellationToken cancellationToken)
    {
        var connection = await base.EstablishConnectionAsync(message, _endPoint, options, cancellationToken);

        return connection;
    }
}

An error is thrown when establishing the connection: SocketException: An unknown, invalid, or unsupported option or level was specified in a getsockopt or setsockopt call.

This happens when Socket.NoDelay is set to true in EstablishConnectionAsync -

Right now the built-in factory can't be used with UDS. To skip that one line I would need to copy at least EstablishConnectionAsync, SocketConnection (it is internal), SocketConnectionNetworkStream and TaskSocketAsyncEventArgs into my own implementation.

Is there a way to detect whether that flag is supported? Or eat the exception if SocketException with an error code of Protocol is thrown?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions