MatrixAI / js-quic

QUIC Networking for TypeScript & JavaScript
https://matrixai.github.io/js-quic/
Apache License 2.0
13 stars 1 forks source link

QUIC client breaks inside electron #121

Open lukasrakauskas opened 1 month ago

lukasrakauskas commented 1 month ago

Describe the bug

Electron has dropped support for external buffers. Thus some methods that this quic library uses are not working in such environment.

Error: Create external arraybuffer failed
    at get connectionId (/Users/lukas.rakauskas/dev/electron-js-quic-reproduce/node_modules/@matrixai/quic/dist/QUICConnection.js:326:36)
    at QUICClient.createQUICClient (/Users/lukas.rakauskas/dev/electron-js-quic-reproduce/node_modules/@matrixai/quic/dist/QUICClient.js:148:45)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  code: 'Unknown'
}

To Reproduce

I've made a reproduce repo. To reproduce pull it run npm install and npm run start https://github.com/lukasrakauskas/electron-js-quic-reproduce

Expected behavior

QUIC client should be able to connect to a server, read and write to streams when created within electron.

Platform

The failing point is reading source ID in javascript, converting Uint8array to external vec seems to solve the external array buffer problem.

// src/native/napi/connection.rs

#[napi]
pub fn source_id(&self) -> External<Vec<u8>> {
  let source_id = self.0.source_id();
  let bytes = source_id.as_ref().to_vec();
  External::new(bytes) 
}

After this, the js fails to read header dcid property that also is Uint8array. To solve this, I've added get_dcid method to Header struct to be used instead of reading dcid directly.

// src/native/napi/packet.rs

#[napi]
pub fn get_dcid(&self) -> External<Vec<u8>> {
  External::new(self.dcid.to_vec()) 
}

Finally the library started to work for my use case

linear[bot] commented 1 month ago

ENG-368 QUIC client breaks inside electron

CMCDragonkai commented 1 month ago

Thanks for reporting this @lukasrakauskas. I'm going to be honest with you here, our company doesn't have the bandwidth to fix this atm, we're focusing on other aspects of our product development that does not involve electron atm. If you can send over a PR, we can validate it works and accept.