Skip to content

Commit ced0d82

Browse files
tabcatclaude
andcommitted
chore(transport-webrtc): shorten comments on send error fix
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 09e6a8a commit ced0d82

3 files changed

Lines changed: 5 additions & 16 deletions

File tree

.github/dictionary.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ dout
1010
getbit
1111
hopr
1212
incrby
13-
libdatachannel
1413
microtask
1514
nothrow
1615
peerStore

packages/transport-webrtc/src/stream.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,7 @@ export class WebRTCStream extends AbstractStream {
145145
this.channel.send(buf)
146146
}
147147
} catch (err: any) {
148-
// channel.send can throw synchronously when the underlying datachannel
149-
// is closed (e.g. because the native libdatachannel state diverged from
150-
// the polyfill's cached readyState). Treat as a transport failure and
151-
// abort the stream so the error surfaces to consumers instead of going
152-
// uncaught.
148+
// channel.send can throw synchronously if the polyfill's cached readyState is stale
153149
this.log.error('error sending datachannel message - %e', err)
154150
this.abort(err)
155151
}

packages/transport-webrtc/test/stream.spec.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,14 @@ describe('Datachannel send errors', () => {
8383
})
8484

8585
it('aborts the stream when underlying datachannel is closed mid-send', async function () {
86-
// the state divergence reproduced here is specific to the
87-
// node-datachannel polyfill; native browser WebRTC does not exhibit it
86+
// polyfill-specific race; native browser WebRTC doesn't exhibit it
8887
if (!isNode && !isElectronMain) {
8988
return this.skip()
9089
}
9190

92-
// open a real datachannel pair so we can trigger the JS-vs-native state
93-
// divergence in the node-datachannel polyfill: peerConnection.close()
94-
// synchronously closes the native datachannel at the C++ level, but the
95-
// polyfill's cached readyState only updates when the onClosed callback
96-
// fires on the next event loop tick. Calling send() in that race window
97-
// passes the readyState guard and reaches the native binding, which
98-
// throws "DataChannel is closed"
91+
// the node-datachannel polyfill's cached readyState updates on the next
92+
// tick after onClosed fires, so closing the peer leaves a window where
93+
// send() passes the guard and hits an already-closed native channel
9994
pcA = new RTCPeerConnection()
10095
pcB = new RTCPeerConnection()
10196
const channelA = pcA.createDataChannel('test', { negotiated: true, id: 91 })
@@ -129,7 +124,6 @@ describe('Datachannel send errors', () => {
129124
log: defaultLogger().forComponent('test')
130125
})
131126

132-
// synchronously close the native peer; polyfill readyState is still 'open'
133127
pcA.close()
134128
expect(channelA.readyState).to.equal('open')
135129

0 commit comments

Comments
 (0)