Comments (12)
Thanks for letting me know, hopefully during the weekend
from kmqtt.
Hello, error 9 bad file descriptor, basically the socket has been closed. Are you still using the client after calling disconnect?
from kmqtt.
No I'm setting the client to null and cancelling the coroutines job right after that.
from kmqtt.
Can you please send a code snippet so that I can try to reproduce it?
from kmqtt.
@davidepianca98 Sure, I have an interface wrapping the client that has 2 methods: subscribe()
/ unsubscribe()
internal interface MyMqttClient {
suspend fun subscribe(onReceive: (String) -> Unit)
suspend fun unsubscribe()
}
here below is the rough implementation:
internal class MyMqttClientImpl {
private var job: Job? = null
private var client: MQTTClient? = null
override suspend fun subscribe(onReceive: (String) -> Unit) {
client = createMqttClient(onReceive)
client?.let { client ->
job = scope.launch {
try {
client.subscribe(listOf(Subscription("my_topic", SubscriptionOptions(Qos.EXACTLY_ONCE))))
client.run()
} catch (ex: Exception) {
// handle exception
}
}
job!!.start()
}
}
override suspend fun unsubscribe() {
client?.let { client ->
client.unsubscribe(listOf("my_topic"))
client.disconnect(ReasonCode.SUCCESS) // crashes here, doesn't crash without this line
}
job?.cancel()
job = null
client = null
}
private fun createMqttClient(onReceive: (String) -> Unit) {
return MQTTClient(
mqttVersion = MQTTVersion.MQTT5,
address = "my_address",
port = 1, // my port
clientId = "my_client_id",
userName = "my_username",
password = "my_password",
tls = null,
) { publish ->
// handle incoming events
}
}
}
After calling subscribe()
and receiving some events, I just call unsubscribe()
and get the crash.
Again, I wanna remind you that this above case works just fine on Android, but crashes on iOS
from kmqtt.
I was not able to reproduce the issue, but I think I have found what potentially can trigger the problem and should be fixed in commit 48cc990.
If you cannot wait for a new build to go out, you may try to either build yourself or do this modification to your code:
override suspend fun unsubscribe() {
job?.cancel()
job = null
client?.let { client ->
client.unsubscribe(listOf("my_topic"))
client.disconnect(ReasonCode.SUCCESS) // crashes here, doesn't crash without this line
}
client = null
}
from kmqtt.
@davidepianca98 Thanks a lot 😃 we can wait for a build.
from kmqtt.
Also please let met know if it works without errors with the code change I sent in the last message
from kmqtt.
@davidepianca98 Once the release is out, I'll report back
from kmqtt.
@davidepianca98 We've tried the fix above and we still get the same issue :(
Do you have an ETA as to when you're going to publish a new release?
from kmqtt.
Please let me know if the new release is working for you
from kmqtt.
@davidepianca98 It seems it's working now on iOS :) thanks
from kmqtt.
Related Issues (20)
- Artifact publication on Maven Central? HOT 3
- iOSBuild failed with Could not find 'openssl-its-simulator-arm64' HOT 2
- ssl server certificate not found (IOS only) HOT 4
- Connecting to a home broker with TCP_PORT & MQTT_PORT HOT 4
- Source and JavaDoc missing from JVM artifacts HOT 1
- java.nio.BufferOverflowException when calling HOT 6
- Is it possible to add a path in MqttClient? HOT 2
- Provide the Client ID inside MQTTDisconnect HOT 2
- Expose the list of the connected client IDs HOT 5
- Delay in receiving published messages HOT 5
- TLSClientSettings from String instead of file path HOT 6
- Socket connection error on windows native HOT 1
- Delay in Publishing message HOT 2
- Can the broker host address be changed HOT 3
- new feature: [MQTTClient] add the timeout connection in parameters HOT 7
- Feature request: Use cklib to package openssl klibs HOT 1
- kmqtt-broker - Error on TLS javax.net.ssl.SSLException : Unable to parse TLS packet header HOT 4
- Ability to subscribe after broker connected HOT 2
- Any way to know if the broker has been started or stopped in the MQTT broker? Something like a listener ?? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kmqtt.