leolabs / ableton-js

Control Ableton Live with Node.js
MIT License
368 stars 46 forks source link

:bug: Fix errors on quick disconnect/connect #42

Closed zoetrope69 closed 2 years ago

zoetrope69 commented 2 years ago

We need to clear timeouts on disconnect because some messages can be removed on disconnect before they are resolved.

Scenario

It looks like when you reconnect Ableton on my Macbook it fires in rapid succession:

  1. Connect
  2. Disconnect
  3. Connect

This seems to be bug but either way this introduces a unhandled race connection if you have code like this:

ableton.on('connect', () => {
  ableton.song.addListener('tempo', console.log);
});

It seems like the sendCommand function can't be resolved in time as the disconnect event clears everything.