emqx / CocoaMQTT

MQTT 5.0 client library for iOS and macOS written in Swift
https://www.emqx.com/en
Other
1.6k stars 420 forks source link

connecting at the same time with mqtt3 and mqtt5 to the same broker does not work #587

Open justme-1968 opened 5 months ago

justme-1968 commented 5 months ago

this is probably not relevant 'in the real world' but during some testing of my client i noticed that connecting from the client at the same time with mqtt3 and mqtt5 to the same broker does not work.

only the last connection will receive messages as expected. the other one will result in an empty topic with the expected payload.

JaylinYu commented 4 months ago

remember, mqtt is a stateful protocol.

justme-1968 commented 4 months ago

what has statefulness todo with that?

state is nothing that should apply between different connections.

one client opening separate connections to two different brokers works as expected. one client opening two mqtt5 connections to the same broker works as expected.

one client opening. mqtt5 and a mqtt3 connection to the same broker results in problems that look like the library is sharing something between the separate connections.

JaylinYu commented 4 months ago

only one MQTT session is allowed in one TCP connection.

justme-1968 commented 4 months ago

why do you think it is the same tcp connection?

the library is handling the connections. i don't even know how you would force it to use the same tcp connection.

the problem is visible with two separate connections that happen to go the the same broker and use different mqtt versions. connecting to different brokers works fine as does using the same matt version to the same broker.

this looks like some internal state is shared by accident.