Skip to content

Commit

Permalink
fix: send data during graceful close (#75)
Browse files Browse the repository at this point in the history
#73 was merged on red, this fixes the build
  • Loading branch information
achingbrain committed Feb 8, 2024
1 parent f5d92da commit f77b9ec
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,21 +172,21 @@
"docs": "aegir docs"
},
"dependencies": {
"@libp2p/interface": "^1.0.0",
"@libp2p/utils": "^5.0.0",
"@libp2p/interface": "^1.1.3",
"@libp2p/utils": "^5.2.5",
"get-iterator": "^2.0.1",
"it-foreach": "^2.0.3",
"it-foreach": "^2.0.6",
"it-pipe": "^3.0.1",
"it-pushable": "^3.2.0",
"uint8arraylist": "^2.4.3"
"it-pushable": "^3.2.3",
"uint8arraylist": "^2.4.8"
},
"devDependencies": {
"@dapplion/benchmark": "^0.2.4",
"@libp2p/interface-compliance-tests": "^5.0.0",
"@libp2p/logger": "^4.0.0",
"@libp2p/mplex": "^10.0.0",
"@libp2p/interface-compliance-tests": "^5.3.1",
"@libp2p/logger": "^4.0.6",
"@libp2p/mplex": "^10.0.15",
"aegir": "^41.1.10",
"it-drain": "^3.0.2",
"it-drain": "^3.0.5",
"it-pair": "^2.0.6",
"it-stream-types": "^2.0.1"
}
Expand Down
4 changes: 2 additions & 2 deletions src/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class YamuxStream extends AbstractStream {
while (buf.byteLength !== 0) {
// wait for the send window to refill
if (this.sendWindowCapacity === 0) {
this.log?.trace('wait for send window capacity', this.status)
this.log?.trace('wait for send window capacity, status %s', this.status)
await this.waitForSendWindowCapacity(options)

// check we didn't close while waiting for send window capacity
Expand Down Expand Up @@ -172,7 +172,7 @@ export class YamuxStream extends AbstractStream {
let resolve: () => void
let reject: (err: Error) => void
const abort = (): void => {
if (this.status === 'open') {
if (this.status === 'open' || this.status === 'closing') {
reject(new CodeError('stream aborted', ERR_STREAM_ABORT))
} else {
// the stream was closed already, ignore the failure to send
Expand Down
7 changes: 5 additions & 2 deletions test/stream.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,11 @@ describe('stream', () => {

await sleep(10)

// the client should close gracefully even though it was waiting to send more data
await client.close()
// the client should fail to close gracefully because there is unsent data
// that will never be sent
await client.close({
signal: AbortSignal.timeout(10)
})
p.end()

await sendPipe
Expand Down

0 comments on commit f77b9ec

Please sign in to comment.