Skip to content

Commit

Permalink
fix: updated for closing stream more safety (for pass tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
JS-AK committed Nov 7, 2024
1 parent 8e898f6 commit fa877df
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/transit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1065,9 +1065,9 @@ class Transit {
*/
_softDeletePendingResStream(id) {
const stream = this.pendingResStreams.get(id);
this.pendingResStreams.delete(id);

if (stream) {
this.pendingResStreams.delete(id);
this._closeStreamIfPossible(stream);
}
}
Expand All @@ -1082,9 +1082,9 @@ class Transit {
*/
_deletePendingResStream(id, origin) {
const stream = this.pendingResStreams.get(id);
this.pendingResStreams.delete(id);

if (stream) {
this.pendingResStreams.delete(id);
this._destroyStreamIfPossible(stream, origin);
}
}
Expand All @@ -1098,15 +1098,11 @@ class Transit {
*/
_softDeletePendingReqStream(id) {
const reqStream = this.pendingReqStreams.get(id);
this.pendingReqStreams.delete(id);
const pass = reqStream ? reqStream.stream : undefined;

if (pass) {
this.pendingReqStreams.delete(id);
this._closeStreamIfPossible(pass);

if (!pass.readableEnded) {
pass.push(null);
}
}
}

Expand All @@ -1120,10 +1116,10 @@ class Transit {
*/
_deletePendingReqStream(id, origin) {
const reqStream = this.pendingReqStreams.get(id);
this.pendingReqStreams.delete(id);
const pass = reqStream ? reqStream.stream : undefined;

if (pass) {
this.pendingReqStreams.delete(id);
this._destroyStreamIfPossible(pass, origin);
}
}
Expand All @@ -1136,7 +1132,7 @@ class Transit {
* @memberof Transit
*/
_destroyStreamIfPossible(stream, origin) {
if (!stream.destroyed) {
if (!stream.destroyed && stream.destroy) {
const message = origin ? `Stream closed by ${origin}` : "Stream internal error";
stream.destroy(new Error(message));
}
Expand All @@ -1149,7 +1145,7 @@ class Transit {
* @memberof Transit
*/
_closeStreamIfPossible(stream) {
if (!stream.readableEnded) {
if (!stream.readableEnded && stream.push) {
stream.push(null);
}
}
Expand Down

0 comments on commit fa877df

Please sign in to comment.