-
Notifications
You must be signed in to change notification settings - Fork 65
fix grpc bugs #40
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
Merged
Merged
fix grpc bugs #40
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,11 +29,37 @@ class GRpcResponse { | |
|
|
||
| async send(res) { | ||
| const methodInfo = this.methodInfo; | ||
| if (methodInfo.responseType) { | ||
| let http2Header = { | ||
| 'content-type': 'application/grpc', | ||
| 'grpc-accept-encoding': 'identity', | ||
| 'accept-encoding': 'identity', | ||
| }; | ||
| let grpcMeta = { | ||
| 'grpc-status': 0, | ||
| 'grpc-message': 'OK', | ||
| }; | ||
| let data = ''; | ||
| if (res.isError) { | ||
| this.meta.rt = Date.now() - this.meta.start; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rt 可以统一设置 |
||
| this.meta.resultCode = '02'; | ||
| http2Header = { | ||
| ...http2Header, | ||
| ':status': 500, // make a unknown http2 status | ||
| }; | ||
| grpcMeta = { | ||
| ...grpcMeta, | ||
| 'grpc-status': 2, // UNKNOWN | ||
| 'grpc-message': res.errorMsg, | ||
| }; | ||
| data = ''; | ||
| } else if (methodInfo.responseType) { | ||
| const responseEncodeStart = Date.now(); | ||
| const responseType = methodInfo.resolvedResponseType; | ||
| const buf = responseType.encode(responseType.fromObject(res.appResponse)).finish(); | ||
| const buf = responseType | ||
| .encode(responseType.fromObject(res.appResponse)) | ||
| .finish(); | ||
| const resSize = buf.length; | ||
| io.reset(); | ||
| io.put(0); | ||
| io.putInt(resSize); | ||
| io.put(buf); | ||
|
|
@@ -42,21 +68,22 @@ class GRpcResponse { | |
| this.meta.data = buf; | ||
| this.meta.rt = Date.now() - this.meta.start; | ||
| this.meta.resSize = resSize + 5; | ||
|
|
||
| this.stream.respond({ | ||
| ':status': 200, | ||
| 'content-type': 'application/grpc', | ||
| 'grpc-accept-encoding': 'identity', | ||
| 'accept-encoding': 'identity', | ||
| }, { waitForTrailers: true }); | ||
| this.stream.on('wantTrailers', () => { | ||
| this.stream.sendTrailers({ | ||
| 'grpc-status': 0, | ||
| 'grpc-message': 'OK', | ||
| }); | ||
| }); | ||
| this.stream.end(io.array()); | ||
| http2Header = { ...http2Header, ':status': 200 }; | ||
| grpcMeta = { | ||
| ...grpcMeta, | ||
| 'grpc-status': 0, | ||
| 'grpc-message': 'OK', | ||
| }; | ||
| data = io.array(); | ||
| } | ||
| if (!this.stream || this.stream.destroyed) { | ||
| return; | ||
| } | ||
| this.stream.respond(http2Header, { waitForTrailers: true }); | ||
| this.stream.on('wantTrailers', () => { | ||
| this.stream.sendTrailers(grpcMeta); | ||
| }); | ||
| this.stream.end(data); | ||
| } | ||
| } | ||
|
|
||
|
|
||
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
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
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
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个应该不用主动触发吧? destroy 以后会自动触发 close
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是的 我的 node 是 v8.x ,在这个版本里 destroy 后收不到 close 事件,所以我手动 emit 了一个
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可能和这个 pr 有关 nodejs/node#23654 v8.x 目前还是有这个问题
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加一个注释?