nanomq / nanomq

An ultra-lightweight and blazing-fast Messaging broker/bus for IoT edge & SDV
https://nanomq.io
MIT License
1.6k stars 193 forks source link

Client cannot connect via websocket: `Incorrect connection header` #1935

Open kuolemaaa opened 6 days ago

kuolemaaa commented 6 days ago

Describe the bug I use Owntracks on android device, Owntracks connects to a MQTT broker to share position with other devices.

I'm trying to migrate from mosquitto to nanomq since it seems to customize the path fo the websocket listener, like

listener.ws.withpath {
    bind = "0.0.0.0:1885/someCustomPathWantedByMe"
}

The problem is that owntracks doesnt manage to connect to the nanomq broker even with a normal websocket connection

listeners.ws {
    bind = "0.0.0.0:1884/"
}

While other clients, like MQTT Explorer & MQTTX, can, without problems.

I'm opening the issue here because it reports: Incorrect connection header

Expected behavior Owntracks should connect to the broker without any problems

Actual Behavior Here a piece of the log of Owntracks

2024-10-30 18:05:20.170 I [DefaultDispatcher-worker-3] MQTTMessageProcessorEndpoint$connectToBroker: Connecting to ws://mqtt.redacteddomain.com:443?# timeout = 30s
2024-10-30 18:05:20.329 E [DefaultDispatcher-worker-3] MQTTMessageProcessorEndpoint$connectToBroker: MQTT client unable to connect to endpoint
MqttException (0) - java.io.IOException: WebSocket Response header: Incorrect connection header
    at androidx.work.impl.utils.WorkForegroundUpdater$1.run(SourceFile:233)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:487)
    at java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:307)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
    at java.lang.Thread.run(Thread.java:1012)
Caused by: java.io.IOException: WebSocket Response header: Incorrect connection header
    at androidx.room.RoomOpenHelper.execute(SourceFile:439)
    at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketNetworkModule.start(SourceFile:28)
    at androidx.work.impl.utils.WorkForegroundUpdater$1.run(SourceFile:66)
    ... 6 more

To Reproduce If possible include actual reproduction test code here. Minimal C test cases are perferred.

Environment Details

Client SDK If possible include the mqtt sdk you used to connect to nanomq Minimal C test cases are perferred.

Additional context Add any other context about the problem here.

kuolemaaa commented 6 days ago

I feel like this is related to the fact that I am using a reverse proxy that is Traefik 3 and maybe is related to this issue https://github.com/nanomq/nanomq/issues/1801

JaylinYu commented 6 days ago

Replied you at another issue thread.

listeners.ws { bind = "0.0.0.0:1884/" } is not even valid without proxy.