fix: stop stream after first pong received (#545)

When connecting to go-IPFS from a webworker, the stream opened by
the ping protocol is never closed.

The change here uses `take` to only receive one buffer from the
remote node before closing the stream.
This commit is contained in:
Alex Potsides
2020-02-03 14:50:40 +00:00
committed by GitHub
parent f39e8f0da9
commit be8fc9daf1
2 changed files with 40 additions and 1 deletions

View File

@ -8,7 +8,7 @@ const errCode = require('err-code')
const crypto = require('libp2p-crypto')
const pipe = require('it-pipe')
const { toBuffer } = require('it-buffer')
const { collect } = require('streaming-iterables')
const { collect, take } = require('streaming-iterables')
const { PROTOCOL, PING_LENGTH } = require('./constants')
@ -29,6 +29,7 @@ async function ping (node, peer) {
const [result] = await pipe(
[data],
stream,
stream => take(1, stream),
toBuffer,
collect
)