quick.flutter icon indicating copy to clipboard operation
quick.flutter copied to clipboard

`setNotifiable` leaks response on Windows, QuickBlue

Open Erhannis opened this issue 3 years ago • 2 comments

After experiencing problems, seeing a cryptic message Warning: Failed to respond to a message. This is a memory leak., and a lot of digging, I've figured out that the setNotifiable message in QuickBlue's Window's quick_blue_plugin.cpp is not responded to. (Like, in the block starting else if (method_name.compare("setNotifiable") == 0), neither result->Success nor result->Error are called, and apparently the relevant objects are garbage collected, triggering the message.) In addition to the warning message, it seems like setNotifiable never actually happens; I don't get messages back.

Here's a log; I added logging to quick_blue_plugin.cpp (with difficulty; OutputDebugString isn't logging anything) for each of the method_name methods; --> FOO means block start, and I log <-S FOO after success and <-E FOO after failure. The key bit in the log is:

--> setNotifiable
Warning: Failed to respond to a message. This is a memory leak.

as well as the observation that there's no corresponding <-E or <-S for setNotifiable.

Launching lib\main.dart on Windows in debug mode...
Building Windows application...
Debug service listening on ws://127.0.0.1:56685/_3neNKBV6wA=/ws
Syncing files to device Windows...
[log] Test: starting gak
[log] Test: started gak
--> connect
asdf 0
asdf 0b
asdf 1
connect bluetoothAddress string: 176600912576074
connect bluetoothAddress stoull: 176600912576074
asdf 2
ConnectAsync bluetoothAddress: 176600912576074
<-S connect
--> connect
asdf 0
asdf 0b
asdf 1
connect bluetoothAddress string: 176600912576074
connect bluetoothAddress stoull: 176600912576074
asdf 2
ConnectAsync bluetoothAddress: 176600912576074
<-S connect
[log] connectTimer
[log] !connected - reconnecting
[log] _handleConnectionChange 176600912576074, connected
--> discoverServices
<-S discoverServices
--> discoverServices
<-S discoverServices
[log] _handleConnectionChange 176600912576074, connected
[log] _handleConnectionChange 176600912576074, connected
[log] _handleConnectionChange 176600912576074, connected
[log] rx connected: true
[log] rx connected: true
[log] _handleServiceDiscovery 176600912576074, 00001800-0000-1000-8000-00805f9b34fb, [00002a00-0000-1000-8000-00805f9b34fb, 00002a01-0000-1000-8000-00805f9b34fb, 00002a04-0000-1000-8000-00805f9b34fb, 00002aa6-0000-1000-8000-00805f9b34fb]
[log] _handleServiceDiscovery 176600912576074, 00001800-0000-1000-8000-00805f9b34fb, [00002a00-0000-1000-8000-00805f9b34fb, 00002a01-0000-1000-8000-00805f9b34fb, 00002a04-0000-1000-8000-00805f9b34fb, 00002aa6-0000-1000-8000-00805f9b34fb]
--> setNotifiable
Warning: Failed to respond to a message. This is a memory leak.
[log] _handleServiceDiscovery 176600912576074, 00001801-0000-1000-8000-00805f9b34fb, [00002a05-0000-1000-8000-00805f9b34fb]
[log] _handleServiceDiscovery 176600912576074, 00001801-0000-1000-8000-00805f9b34fb, [00002a05-0000-1000-8000-00805f9b34fb]
[log] _handleServiceDiscovery 176600912576074, 0000180a-0000-1000-8000-00805f9b34fb, [00002a29-0000-1000-8000-00805f9b34fb, 00002a24-0000-1000-8000-00805f9b34fb, 00002a25-0000-1000-8000-00805f9b34fb, 00002a27-0000-1000-8000-00805f9b34fb, 00002a26-0000-1000-8000-00805f9b34fb, 00002a28-0000-1000-8000-00805f9b34fb, 00002a23-0000-1000-8000-00805f9b34fb]
[log] _handleServiceDiscovery 176600912576074, 0000180a-0000-1000-8000-00805f9b34fb, [00002a29-0000-1000-8000-00805f9b34fb, 00002a24-0000-1000-8000-00805f9b34fb, 00002a25-0000-1000-8000-00805f9b34fb, 00002a27-0000-1000-8000-00805f9b34fb, 00002a26-0000-1000-8000-00805f9b34fb, 00002a28-0000-1000-8000-00805f9b34fb, 00002a23-0000-1000-8000-00805f9b34fb]
[log] _handleServiceDiscovery 176600912576074, 0000feee-0000-1000-8000-00805f9b34fb, []
[log] _handleServiceDiscovery 176600912576074, 0000feee-0000-1000-8000-00805f9b34fb, [fb005c51-02e7-f387-1cad-8acd2d8df0c8, fb005c52-02e7-f387-1cad-8acd2d8df0c8, fb005c53-02e7-f387-1cad-8acd2d8df0c8]
[log] _handleServiceDiscovery 176600912576074, 0000180d-0000-1000-8000-00805f9b34fb, []
[log] _handleServiceDiscovery 176600912576074, 0000180d-0000-1000-8000-00805f9b34fb, [00002a37-0000-1000-8000-00805f9b34fb]
[log] _handleServiceDiscovery 176600912576074, 0000180f-0000-1000-8000-00805f9b34fb, [00002a19-0000-1000-8000-00805f9b34fb]
[log] _handleServiceDiscovery 176600912576074, 0000180f-0000-1000-8000-00805f9b34fb, [00002a19-0000-1000-8000-00805f9b34fb]
[log] _handleServiceDiscovery 176600912576074, fb005c20-02e7-f387-1cad-8acd2d8df0c8, []
[log] _handleServiceDiscovery 176600912576074, fb005c20-02e7-f387-1cad-8acd2d8df0c8, [fb005c21-02e7-f387-1cad-8acd2d8df0c8, fb005c22-02e7-f387-1cad-8acd2d8df0c8, fb005c26-02e7-f387-1cad-8acd2d8df0c8]
[log] _handleServiceDiscovery 176600912576074, 6217ff4b-fb31-1140-ad5a-a45545d7ecf3, []
[log] connectTimer
[log] _handleServiceDiscovery 176600912576074, 6217ff4b-fb31-1140-ad5a-a45545d7ecf3, [6217ff4c-c8ec-b1fb-1380-3ad986708e2d, 6217ff4d-91bb-91d0-7e2a-7cd3bda8a1f3]
[log] _handleServiceDiscovery 176600912576074, fb005c80-02e7-f387-1cad-8acd2d8df0c8, []
[log] _handleServiceDiscovery 176600912576074, fb005c80-02e7-f387-1cad-8acd2d8df0c8, [fb005c81-02e7-f387-1cad-8acd2d8df0c8, fb005c82-02e7-f387-1cad-8acd2d8df0c8]
[log] connectTimer
[log] connectTimer
[log] connectTimer
[log] connectTimer
[log] Test: stopping gak
--> disconnect
<-S disconnect
--> disconnect
<-S disconnect
[log] cancelPeripheralConnection 176600912576074
[log] connectTimer
[log] Test: stopped gak
[log] Test: sleeping
[log] Test: done

Erhannis avatar Aug 19 '22 06:08 Erhannis

Thanks for your report. Does it happen on the old implementation or the new one?

  • old implementation in https://github.com/woodemi/quick_blue
    SetNotifiableAsync(*it->second, service, characteristic, bleInputProperty);
    result->Success(nullptr);
  • new implementation in this repo
    auto bluetoothAgent = *it->second;
    auto async_c = bluetoothAgent.GetCharacteristicAsync(service, characteristic);
    async_c.Completed([&, result_pointer = result.get()]
        (IAsyncOperation<GattCharacteristic> const& sender, AsyncStatus const args) {
          // FIXME https://github.com/woodemi/quick.flutter/pull/31#issuecomment-1159213902
          auto c = sender.GetResults();
          if (c == nullptr) {
            result_pointer->Error("IllegalArgument", "Unknown characteristic:" + characteristic);
            return;
          }
          SetNotifiableAsync(bluetoothAgent, c, bleInputProperty);
          result_pointer->Success(nullptr);
        });

Sunbreak avatar Aug 19 '22 09:08 Sunbreak

The new one. I would suspect the other methods in that file with the same async_c.Completed configuration express the same behavior, but haven't checked.

Erhannis avatar Aug 19 '22 14:08 Erhannis