chrvadala / node-ble

Bluetooth Low Energy (BLE) library written with pure Node.js (no bindings) - baked by Bluez via DBus
https://www.npmjs.com/package/node-ble
MIT License
320 stars 47 forks source link

MaxListenersExceededWarning: Possible EventEmitter memory leak detected when calling device::gatt() #76

Open naugehyde opened 1 month ago

naugehyde commented 1 month ago

Running the code below with appropriate command line args (mac_address and timeout. eg node test.js 'FF:FF:FF:FF:FF:FF' 15000) causes, after 10 trials in my case, the following warning to appear on the console repeatedly, one for each of the gatt server's primary service's characteristics:

(node:230077) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 {"path":"/org/bluez/hci0/dev_XX_XX_XX_XX_XX_XX/service000e/char00XX","interface":"org.freedesktop.DBus.Properties","member":"PropertiesChanged"} listeners added to [EventEmitter]. Use emitter.setMaxListeners() to increase limit


const {createBluetooth} = require('node-ble')
const {bluetooth, destroy} = createBluetooth()
const { argv } = require('node:process');

async function main(){

  const adapter = await bluetooth.defaultAdapter()
  const device = await adapter.waitDevice(argv[2])

  try{await adapter.startDiscovery()} catch{}
  var trials=0

  async function search(){
      await device.connect()
      console.log(`GATT trial #${++trials}...`)
      const gatt = await device.gatt()
      await device.disconnect()
 }

setInterval(() => {
  search()
},argv[3]);
search()
}
main()