Skip to content

QUIC client breaks inside electron #121

@lukasrakauskas

Description

@lukasrakauskas

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

  • Device: Macbook M1 Pro
  • OS: macOS Sonoma 14.5

Possible fix

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions