Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: catch pipe errors #678

Merged
merged 2 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions src/identify/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class IdentifyService {
* @param {*} options.stream
* @param {Connection} options.connection
*/
_handleIdentify ({ connection, stream }) {
async _handleIdentify ({ connection, stream }) {
let publicKey = Buffer.alloc(0)
if (this.peerId.pubKey) {
publicKey = this.peerId.pubKey.bytes
Expand All @@ -223,12 +223,16 @@ class IdentifyService {
protocols: Array.from(this._protocols.keys())
})

pipe(
[message],
lp.encode(),
stream,
consume
)
try {
await pipe(
[message],
lp.encode(),
stream,
consume
)
} catch (err) {
log.error('could not respond to identify request', err)
}
}

/**
Expand All @@ -239,17 +243,16 @@ class IdentifyService {
* @param {Connection} options.connection
*/
async _handlePush ({ connection, stream }) {
const [data] = await pipe(
[],
stream,
lp.decode(),
take(1),
toBuffer,
collect
)

let message
try {
const [data] = await pipe(
[],
stream,
lp.decode(),
take(1),
toBuffer,
collect
)
message = Message.decode(data)
} catch (err) {
return log.error('received invalid message', err)
Expand Down
2 changes: 1 addition & 1 deletion src/metrics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class Metrics {

const _sink = stream.sink
stream.sink = source => {
pipe(
return pipe(
source,
tap(chunk => metrics._onMessage({
remotePeer,
Expand Down
4 changes: 2 additions & 2 deletions src/pnet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const handshake = require('it-handshake')
const { NONCE_LENGTH } = require('./key-generator')
const debug = require('debug')
const log = debug('libp2p:pnet')
log.err = debug('libp2p:pnet:err')
log.error = debug('libp2p:pnet:err')

/**
* Takes a Private Shared Key (psk) and provides a `protect` method
Expand Down Expand Up @@ -69,7 +69,7 @@ class Protector {
// Decrypt all inbound traffic
createUnboxStream(remoteNonce, this.psk),
external
)
).catch(log.error)

return internal
}
Expand Down
2 changes: 1 addition & 1 deletion src/upgrader.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ class Upgrader {
}

// Pipe all data through the muxer
pipe(upgradedConn, muxer, upgradedConn)
pipe(upgradedConn, muxer, upgradedConn).catch(log.error)
}

const _timeline = maConn.timeline
Expand Down