fix: clean up orchestration history streams#314
Open
YunchuWang wants to merge 1 commit into
Open
Conversation
…ce leak getOrchestrationHistory() calls stream.removeAllListeners() but does not call stream.destroy() or register a no-op error handler afterward. This means stream resources are never explicitly released, and a late gRPC error event after removeAllListeners() could crash the Node.js process with an unhandled error. Add stream.destroy() and a no-op error handler in both the 'end' and 'error' stream handlers, matching the established cleanup pattern already used in task-hub-grpc-worker.ts. Add 8 unit tests verifying stream destroy on success/error, late error event safety, input validation, and error code handling. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses a resource-leak / unhandled-error risk in the core SDK client by ensuring TaskHubGrpcClient.getOrchestrationHistory() properly tears down its gRPC history stream, aligning cleanup behavior with the existing worker stream cleanup pattern.
Changes:
- Destroy the history stream and attach a terminal no-op
"error"handler afterremoveAllListeners()on both"end"and"error"paths. - Add a focused Jest test suite covering cleanup on success, common gRPC error cases, and “late error” safety after cleanup.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/durabletask-js/src/client/client.ts | Ensures history streams are fully cleaned up (no-op error handler + destroy) on end/error. |
| packages/durabletask-js/test/client-stream-cleanup.spec.ts | Adds targeted tests validating stream teardown and late-error safety behaviors. |
Comment on lines
+51
to
+54
| const event = new pb.HistoryEvent(); | ||
| event.setEventid(1); | ||
| event.setTimestamp(Timestamp.fromDate(new Date())); | ||
| const orchestratorStarted = new pb.OrchestratorStartedEvent(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #215
Testing
npm test -w @microsoft/durabletask-js -- --runTestsByPath test/client-stream-cleanup.spec.tsnpm run build:core