Skip to content

[Issue] UnregisterGattApplication Bug #65

@uriel-kluk

Description

@uriel-kluk

Description

Exception Thrown When Unregistering GATT Application in Incorrect Order

Environment

  • OS Distro: _Ubuntu v22.04
  • Linux.Bluetooth Version:5.66

Severity (1-5)

4=(ends up leaking if not addressed)

Steps To Reproduce

Steps to reproduce the behavior:

  1. Modify the UnregisterGattApplication in the GattServer.cs class with Debug traces and try/catch
  2. Run any sample that starts the GattServer and registers an application service with at least one characteristic
  3. Call the unregister and look at the traces

Expected Behavior

You should not see exceptions thrown

Current traces with modified code

Error unregistering GATT application: Tmds.DBus.DBusException: org.freedesktop.DBus.Error.UnknownObject: Method "UnregisterApplication" with signature "o" on interface "org.bluez.GattManager1" doesn't exist

   at Tmds.DBus.DBusConnection.CallMethodAsync(Message msg, Boolean checkConnected, Boolean checkReplyType)
   at Tmds.DBus.Connection.CallMethodAsync(Message message)
   at Tmds.DBus.CodeGen.DBusObjectProxy.SendMethodReturnReaderAsync(String iface, String member, Nullable`1 inSignature, MessageWriter writer)
   at Linux.Bluetooth.GattServer.GattServer.UnregisterGattApplication() in C:\_Src\Sdbx\Linux.Bluetooth\src\Linux.Bluetooth\GattServer\GattServer.cs:line 162

Additional context

Here is the code fix, with the additional traces to demonstrate it works:

    public async Task UnregisterGattApplication()
    {
      try
      {
        if (_gattApplication is not null)
        {
          await _gattManager.UnregisterApplicationAsync(_gattApplication.ObjectPath);

          foreach (GattService service in _gattApplication.Services)
          {
            foreach (GattCharacteristicServer characteristic in service.Characteristics)
            {
              // delete this
              foreach (GattDescriptor descriptor in characteristic.Descriptors)
              {
                Debug.WriteLine($"Unregistering descriptor {descriptor.ObjectPath}...");
              }

              Connection.UnregisterObjects(characteristic.Descriptors);
            }

            // delete this
            foreach (var characteristic in service.Characteristics)
            {
              Debug.WriteLine($"Unregistering characteristic {characteristic.ObjectPath}...");
            }

            Connection.UnregisterObjects(_gattApplication.Services);
          }
        }
      }
      catch (Exception ex)
      {
        Console.Error.WriteLine($"Error unregistering GATT application: {ex}");
      }

      _gattApplication = null;
    }

Metadata

Metadata

Assignees

Labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions