Ubuntu – The bluetooth service cannot not restart properly : needs to be done in two steps

16.04bluetoothsystemd

The bluetooth service cannot not restart properly :

$ sudo service bluetooth restart;service bluetooth status
● bluetooth.service - Bluetooth service
   Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
   Active: active (running) since jeu. 2020-02-27 11:18:05 CET; 398ms ago
     Docs: man:bluetoothd(8)
 Main PID: 18310 (bluetoothd)
   Status: "Running"
   CGroup: /system.slice/bluetooth.service
           └─18310 /usr/lib/bluetooth/bluetoothd

févr. 27 11:18:05 sebastien-B206 bluetoothd[18310]: gatt-time-server: Input/output error (5)
févr. 27 11:18:05 sebastien-B206 bluetoothd[18310]: Not enough free handles to register service
févr. 27 11:18:05 sebastien-B206 bluetoothd[18310]: Not enough free handles to register service
févr. 27 11:18:05 sebastien-B206 bluetoothd[18310]: Sap driver initialization failed.
févr. 27 11:18:05 sebastien-B206 bluetoothd[18310]: sap-server: Operation not permitted (1)
févr. 27 11:18:05 sebastien-B206 bluetoothd[18310]: Endpoint registered: sender=:1.55 path=/MediaEndpoint/A2DPSource
févr. 27 11:18:05 sebastien-B206 bluetoothd[18310]: Endpoint registered: sender=:1.55 path=/MediaEndpoint/A2DPSink
févr. 27 11:18:05 sebastien-B206 bluetoothd[18310]: Endpoint registered: sender=:1.43 path=/MediaEndpoint/A2DPSource
févr. 27 11:18:05 sebastien-B206 bluetoothd[18310]: Endpoint registered: sender=:1.43 path=/MediaEndpoint/A2DPSink
févr. 27 11:18:05 sebastien-B206 bluetoothd[18310]: RFCOMM server failed for Headset Voice gateway: rfcomm_bind: Address already in use (98)

It needs to be done in two steps (see the last line of the status) :

$ sudo service bluetooth stop;sudo service bluetooth start;service bluetooth status
● bluetooth.service - Bluetooth service
   Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
   Active: active (running) since jeu. 2020-02-27 11:20:12 CET; 2s ago
     Docs: man:bluetoothd(8)
 Main PID: 18390 (bluetoothd)
   Status: "Running"
   CGroup: /system.slice/bluetooth.service
           └─18390 /usr/lib/bluetooth/bluetoothd

févr. 27 11:20:12 sebastien-B206 bluetoothd[18390]: Not enough free handles to register service
févr. 27 11:20:12 sebastien-B206 bluetoothd[18390]: Not enough free handles to register service
févr. 27 11:20:12 sebastien-B206 bluetoothd[18390]: Sap driver initialization failed.
févr. 27 11:20:12 sebastien-B206 bluetoothd[18390]: sap-server: Operation not permitted (1)
févr. 27 11:20:12 sebastien-B206 bluetoothd[18390]: Endpoint registered: sender=:1.55 path=/MediaEndpoint/A2DPSource
févr. 27 11:20:12 sebastien-B206 bluetoothd[18390]: Endpoint registered: sender=:1.55 path=/MediaEndpoint/A2DPSink
févr. 27 11:20:12 sebastien-B206 bluetoothd[18390]: Endpoint registered: sender=:1.43 path=/MediaEndpoint/A2DPSource
févr. 27 11:20:12 sebastien-B206 bluetoothd[18390]: Endpoint registered: sender=:1.43 path=/MediaEndpoint/A2DPSink
févr. 27 11:20:12 sebastien-B206 bluetoothd[18390]: RFCOMM server failed for Headset Voice gateway: rfcomm_bind: Address already in use (98)
févr. 27 11:20:15 sebastien-B206 systemd[1]: Started Bluetooth service.

I tried adding the RestartSec=5 parameter in the [Service] section of /lib/systemd/system/bluetooth.service (man systemd.service) but it didn't work :

$ sudo systemctl edit --full bluetooth
$ systemctl cat bluetooth | grep RestartSec
RestartSec=5
$ sudo systemctl daemon-reload
$ sudo service bluetooth restart;service bluetooth status
● bluetooth.service - Bluetooth service
   Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
   Active: active (running) since jeu. 2020-02-27 11:30:28 CET; 524ms ago
     Docs: man:bluetoothd(8)
 Main PID: 18830 (bluetoothd)
   Status: "Running"
   CGroup: /system.slice/bluetooth.service
           └─18830 /usr/lib/bluetooth/bluetoothd

févr. 27 11:30:28 sebastien-B206 bluetoothd[18830]: gatt-time-server: Input/output error (5)
févr. 27 11:30:28 sebastien-B206 bluetoothd[18830]: Not enough free handles to register service
févr. 27 11:30:28 sebastien-B206 bluetoothd[18830]: Not enough free handles to register service
févr. 27 11:30:28 sebastien-B206 bluetoothd[18830]: Sap driver initialization failed.
févr. 27 11:30:28 sebastien-B206 bluetoothd[18830]: sap-server: Operation not permitted (1)
févr. 27 11:30:28 sebastien-B206 bluetoothd[18830]: Endpoint registered: sender=:1.55 path=/MediaEndpoint/A2DPSource
févr. 27 11:30:28 sebastien-B206 bluetoothd[18830]: Endpoint registered: sender=:1.55 path=/MediaEndpoint/A2DPSink
févr. 27 11:30:28 sebastien-B206 bluetoothd[18830]: Endpoint registered: sender=:1.43 path=/MediaEndpoint/A2DPSource
févr. 27 11:30:28 sebastien-B206 bluetoothd[18830]: Endpoint registered: sender=:1.43 path=/MediaEndpoint/A2DPSink
févr. 27 11:30:28 sebastien-B206 bluetoothd[18830]: RFCOMM server failed for Headset Voice gateway: rfcomm_bind: Address already in use (98)

Here is my bluetooth.service configuration :

$ systemctl cat bluetooth
# /lib/systemd/system/bluetooth.service
[Unit]
Description=Bluetooth service
Documentation=man:bluetoothd(8)
ConditionPathIsDirectory=/sys/class/bluetooth

[Service]
Type=dbus
BusName=org.bluez
ExecStart=/usr/lib/bluetooth/bluetoothd
NotifyAccess=main
#WatchdogSec=10
#Restart=on-failure
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
LimitNPROC=1
RestartSec=5

[Install]
WantedBy=bluetooth.target,suspend.target
Alias=dbus-org.bluez.service

EDIT0 : Just rebooted then :

$ sudo systemctl restart bluetooth
$ systemctl status -n 20 bluetooth
● bluetooth.service - Bluetooth service
   Loaded: loaded (/etc/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
   Active: active (running) since jeu. 2020-02-27 17:23:24 CET; 2min 42s ago
     Docs: man:bluetoothd(8)
 Main PID: 5050 (bluetoothd)
   Status: "Running"
   CGroup: /system.slice/bluetooth.service
           └─5050 /usr/lib/bluetooth/bluetoothd

févr. 27 17:23:24 sebastien-B206 systemd[1]: Started Bluetooth service.
févr. 27 17:23:25 sebastien-B206 bluetoothd[5050]: Starting SDP server
févr. 27 17:23:25 sebastien-B206 bluetoothd[5050]: Bluetooth management interface 1.10 initialized
févr. 27 17:23:25 sebastien-B206 bluetoothd[5050]: Failed to obtain handles for "Service Changed" characteristic
févr. 27 17:23:25 sebastien-B206 bluetoothd[5050]: Not enough free handles to register service
févr. 27 17:23:25 sebastien-B206 bluetoothd[5050]: Error adding Link Loss service
févr. 27 17:23:25 sebastien-B206 bluetoothd[5050]: Not enough free handles to register service
févr. 27 17:23:25 sebastien-B206 bluetoothd[5050]: Not enough free handles to register service
févr. 27 17:23:25 sebastien-B206 bluetoothd[5050]: Not enough free handles to register service
févr. 27 17:23:25 sebastien-B206 bluetoothd[5050]: Current Time Service could not be registered
févr. 27 17:23:25 sebastien-B206 bluetoothd[5050]: gatt-time-server: Input/output error (5)
févr. 27 17:23:25 sebastien-B206 bluetoothd[5050]: Not enough free handles to register service
févr. 27 17:23:25 sebastien-B206 bluetoothd[5050]: Not enough free handles to register service
févr. 27 17:23:25 sebastien-B206 bluetoothd[5050]: Sap driver initialization failed.
févr. 27 17:23:25 sebastien-B206 bluetoothd[5050]: sap-server: Operation not permitted (1)
févr. 27 17:23:25 sebastien-B206 bluetoothd[5050]: Endpoint registered: sender=:1.65 path=/MediaEndpoint/A2DPSource
févr. 27 17:23:25 sebastien-B206 bluetoothd[5050]: Endpoint registered: sender=:1.65 path=/MediaEndpoint/A2DPSink
févr. 27 17:23:25 sebastien-B206 bluetoothd[5050]: Endpoint registered: sender=:1.42 path=/MediaEndpoint/A2DPSource
févr. 27 17:23:25 sebastien-B206 bluetoothd[5050]: Endpoint registered: sender=:1.42 path=/MediaEndpoint/A2DPSink
févr. 27 17:23:25 sebastien-B206 bluetoothd[5050]: RFCOMM server failed for Headset Voice gateway: rfcomm_bind: Address already in use (98)

EDIT1 : rfkill list output :

$ rfkill list
0: hci0: Bluetooth
    Soft blocked: no
    Hard blocked: no
1: phy0: Wireless LAN
    Soft blocked: no
    Hard blocked: no

EDIT2 : Tried this but it didn't solve the RFCOMM server failed for Headset Voice gateway: rfcomm_bind: Address already in use (98) pb.

CONCLUSION : I added the --noplugin=sap option to the ExecStart= command line from a solution proposed by @6666 and it solved my restart pb. Still have the other errors but bluetooth is working fine after each bluetooth service restart so who cares about them 🙂

Best Answer

  • Focus on the first substantial error Sap driver initialization failed since it cascades into the last error you highlighted:

    RFCOMM server failed for Headset Voice gateway: rfcomm_bind: Address already in use (98).

    Start debugging top-down. Usually then the last errors solve themselves. For general referencing, here are some sample bluetooth config files for audio.

  • Related Question