Skip to content

MqttConnectionHandler race condition #2173

@xemed-ahope

Description

@xemed-ahope

The initial state of MqttConnectionHandler can result in a NullReferenceException in the time between generic host starup and "full" startup. In my test environment this occurs consistently. For a workaround, I explicitly pull and inject the dependencies by calling StartAsync after building and prior to starting the host.

As I understand it, the connection should be terminated rather than remain unhandled in an invalid state.

    public override async Task OnConnectedAsync(ConnectionContext connection)
    {
        ...
        var clientHandler = ClientHandler;
        if (clientHandler != null)
        {
            await clientHandler(adapter).ConfigureAwait(false);
        }
+       else
+       {
+           connection.Abort();
+       }
    }

Initially called out by @xljiulang in #2102 (comment)

Edited for clarity and to sync up to current master

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions