Skip to content

Commit

Permalink
just set a different abort controller instead of duplicating internal…
Browse files Browse the repository at this point in the history
… disconnect logic
  • Loading branch information
liamcottle committed Nov 19, 2024
1 parent 96237cf commit d0dac32
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions src/js/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,28 +113,21 @@ class Connection {
return;
}

// disconnect
// fix issue with http connection abort controller
if(GlobalState.connection instanceof HttpConnection){

// fixme: this should probably be fixed in @meshtastic/js directly
// calling disconnect() on an HttpConnection during the initial config fetching locks up the web page
// this is caused by an infinite loop of errors with the below message:
// ERROR [iMeshDevice:HttpConnection] ReadFromRadio ❌ signal is aborted without reason
// to fix this, we are calling the same internal methods that disconnect() does
// however, we are skipping the call to abortController.abort(), this reliably fixes the issue
// and no longer locks up the page, however we still get packet callbacks until the config phase finishes
// I don't really care if a few more packets come in after disconnecting
GlobalState.connection.updateDeviceStatus(Types.DeviceStatusEnum.DeviceDisconnected);
if(GlobalState.connection.readLoop){
clearInterval(GlobalState.connection.readLoop);
GlobalState.connection.complete();
}

} else {
// disconnect normally
GlobalState.connection.disconnect();
// to fix this, we are just overwriting the internal abortController with a new instance that won't abort the pending internal http requests
// this reliably fixes the issue and no longer locks up the page, however we still get packet callbacks until the config phase finishes
// I don't really care if a few more packets come in after disconnecting, so this will do for now
// fixme: this should probably be fixed in @meshtastic/js directly, probably by breaking out of the while loop if an abort error is received
GlobalState.connection.abortController = new AbortController();
}

// disconnect
GlobalState.connection.disconnect();

// update ui
GlobalState.isConnected = false;

Expand Down

0 comments on commit d0dac32

Please sign in to comment.