Skip to content

Instantly share code, notes, and snippets.

@guest271314
Created September 10, 2025 05:22
Show Gist options
  • Save guest271314/af8fde46a70bfe4b75df969f14569c23 to your computer and use it in GitHub Desktop.
Save guest271314/af8fde46a70bfe4b75df969f14569c23 to your computer and use it in GitHub Desktop.
When all you need to do for "Node.js compatibility" is return 0...

When all you need to do for compatibility is return 0...

Testing @fails-components/webtransport in node, deno, and bun, when the code was written exclusively for Node.js, depending on Node.js Addon has been interesting this.socketInt.getSendQueueCount is undefined in transports/http3-quiche/lib/socket.js #409 If this.socketInt.getSendQueueCount is undefined define function that returns 0; support Deno #412.

Deno throws

DENO_COMPAT=1 deno -A wt-server.js
WebTransport server started
terminate called after throwing an instance of 'Napi::Error'
  what():  this.socketInt.getSendQueueCount is not a function
Aborted
DEBUG=webtransport* DENO_COMPAT=1 deno -A wt-client.js
  webtransport:native(116896) load webtransport binary: ./webtransport.node +0ms
terminate called after throwing an instance of 'Napi::Error'
  what():  this.socketInt.getSendQueueCount is not a function
Aborted

So, what the hell does this.socketInt.getSendQueueCount do?

That function is referenced twice in the source code, in webtransport/transports/http3-quiche/lib/socket.js

const blocked = this.socketInt.getSendQueueCount() > 0
// ...
     this.socketInt.getSendQueueCount() === 0 && 
// ...

All I got was 0s, ending with a Segmentation fault.

DENO_COMPAT=1 DEBUG=webtransport* deno -A wt-client.js
  webtransport:native(34516) load webtransport binary: ./webtransport.node +0ms
sendPacket false 0
# ...
sendPacket true 0
Segmentation fault

A little poking around... Bun just returns 0 in src/js/node/dgram.ts

Socket.prototype.getSendQueueCount = function () {
  return 0;
  // return this[kStateSymbol].handle.getSendQueueCount();
};

Voila, Deno works, is "Node.js compatible" - as server and client

this.socketInt = createSocket({
  type: result.family === 4 ? "udp4" : "udp6",
  ipv6Only: this.forceIpv6
});
if (!this.socketInt.getSendQueueCount) {
  this.socketInt.getSendQueueCount = function() { return 0 }
}
DEBUG=webtransport* DENO_COMPAT=1 deno -A wt-server.js
  webtransport:native(117029) load webtransport binary: ./webtransport.node +0ms
WebTransport server started
(node:117029) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
Promise { <pending> }
4 20971520
WebTransport readable closed
WebTransport writable closed
  webtransport:http3wtstream(117029) callback streamFinal +0ms
  webtransport:http3wtstream(117029) callback streamFinal +20ms
  webtransport:httpwtsession(117029) onClose +0ms
Stream 0
Session done
Clients 0
#...
DEBUG=webtransport* DENO_COMPAT=1 deno -A wt-client.js
  webtransport:native(117067) load webtransport binary: ./webtransport.node +0ms
(node:117067) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
WebTransport client ready
{ outgoingTotalLength: 20971520 }
Outgoing total length 20971520 written.
  webtransport:http3wtstream(117067) callback streamFinal +0ms
  webtransport:http3wtstream(117067) callback streamFinal +8ms
  webtransport:httpwtsession(117067) closeinfo { closeCode: 4999, reason: 'Done streaming.' } +0ms
  webtransport:http3wtstream(117067) callback stopSending +7ms
  webtransport:http3wtstream(117067) callback resetStream +1ms
  webtransport:httpwtsession(117067) onClose +5ms
{ closeCode: 4999, reason: "Done streaming." }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment