From 4edc7f473f3002842f7d1074456e20ae6cc6fbf3 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 30 Nov 2023 14:59:42 +0000 Subject: [PATCH 1/2] fix: read stream data using lp stream --- .../libp2p-daemon-protocol/src/stream-handler.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/libp2p-daemon-protocol/src/stream-handler.ts b/packages/libp2p-daemon-protocol/src/stream-handler.ts index 45546445..da970aa3 100644 --- a/packages/libp2p-daemon-protocol/src/stream-handler.ts +++ b/packages/libp2p-daemon-protocol/src/stream-handler.ts @@ -27,16 +27,12 @@ export class StreamHandler { /** * Read and decode message */ - async read (): Promise { - // @ts-expect-error decoder is really a generator - const msg = await this.decoder.next() - if (msg.value != null) { - return msg.value.subarray() + async read (): Promise { + try { + return await this.lp.read() + } catch (err) { + log('read received no value, closing stream', err) } - - log('read received no value, closing stream') - // End the stream, we didn't get data - await this.close() } async write (msg: Uint8Array | Uint8ArrayList): Promise { From cf190506327aaadb9c87a8581e1e2c13123c0e72 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 30 Nov 2023 15:00:30 +0000 Subject: [PATCH 2/2] chore: log as error --- packages/libp2p-daemon-protocol/src/stream-handler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/libp2p-daemon-protocol/src/stream-handler.ts b/packages/libp2p-daemon-protocol/src/stream-handler.ts index da970aa3..76b2d2c8 100644 --- a/packages/libp2p-daemon-protocol/src/stream-handler.ts +++ b/packages/libp2p-daemon-protocol/src/stream-handler.ts @@ -31,7 +31,7 @@ export class StreamHandler { try { return await this.lp.read() } catch (err) { - log('read received no value, closing stream', err) + log.error('read received no value', err) } }