Skyost / Bonsoir

A Zeroconf library that allows you to discover network services and to broadcast your own. Based on Apple Bonjour and Android NSD.
http://bonsoir.skyost.eu/
Other
100 stars 43 forks source link

Crashes related to messages being sent from native to Flutter on non-platform thread #78

Closed barkdoll closed 6 months ago

barkdoll commented 6 months ago

Describe the bug When starting the app with bonsoir, an error is logged during debugging:

[ERROR:flutter/shell/common/shell.cc(1015)] The 'fr.skyost.bonsoir.discovery.96911' channel sent a message 
from native to Flutter on a non-platform thread. Platform channel messages must be sent on the platform thread. 
Failure to do so may result in data loss or crashes, and must be fixed in the plugin 
or application code creating that channel.

On Windows, the debug builds will sometimes crash with a C++ error related to the bonsoir .dll file (see attached screenshot).

To Reproduce Steps to reproduce the behavior:

  1. Set up a discovery instance in an application via:

    BonsoirDiscovery? discoveryInstance;
    
    Future<void> startDiscovery() async {
    discoveryInstance = BonsoirDiscovery(type: '_my-service._tcp');
    await discoveryInstance!.ready;
    discoveryInstance!.eventStream!.listen((event) {
      log(event); // use logger or print however you want
    });
    await discoveryInstance!.start();
    }
  2. Upon startup you should see the debug [ERROR:flutter/shell/common/...] message above once the discovery execution starts running.
  3. Set up a button to stop/teardown previous discovery, create a new discovery instance, and start discovery again with new instance. Example:
    
    Future<void> restartDiscovery() async {
    if (discoveryInstance != null) {
    await discoveryInstance!.stop();
    }
    await startDiscovery();
    }

4. App may or may not crash and close out or show popup like the one attached below.

**Expected behavior**
- Expecting discovery to work without any crashing / instability coming from platform-channel message handling. 
- Expecting the ability to stop and start discovery as needed.

**Screenshots**
![image](https://github.com/Skyost/Bonsoir/assets/22645556/815c2619-d273-4b73-9ead-f25245097120)

**Desktop (please complete the following information):**
 - OS: Windows 11
 - Browser: No browser, just debugging the app with native Windows
 - Version 5.1.1
Skyost commented 6 months ago

It's not an error, it's just a warning. This has nothing to do with the crash you're encountering. I'm gonna investigate on it to see what I can do, but it seems related to the following line : https://github.com/Skyost/Bonsoir/blob/master/packages/bonsoir_windows/windows/bonsoir_action.cpp#L93.

For the warning, feel free to thumb up this issue : https://github.com/flutter/flutter/issues/79213.

Skyost commented 6 months ago

Also for the warnings, I suggest you to follow this issue : https://github.com/flutter/flutter/issues/134346.

barkdoll commented 6 months ago

I set up a barebones example project, but I cannot seem to reproduce it. I am sorry to have wasted your time. It must be something specific to my project. I will keep looking into the issue on my end and if I cannot find a reproducible scenario outside of my application, I will look for a solution that resolves what is exclusively affecting me. Thanks for looking into it anyways.

Skyost commented 6 months ago

I am sorry to have wasted your time. It must be something specific to my project. I will keep looking into the issue on my end and if I cannot find a reproducible scenario outside of my application, I will look for a solution that resolves what is exclusively affecting me.

No problem, it was clearly a bug from Bonsoir 😉