Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
8d18c6ed
Commit
8d18c6ed
authored
7 years ago
by
murgatroid99
Browse files
Options
Downloads
Patches
Plain Diff
Fix race between destroying call after status and handling write failure
parent
c80d3321
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/node/ext/call.cc
+8
-0
8 additions, 0 deletions
src/node/ext/call.cc
src/node/src/client.js
+10
-2
10 additions, 2 deletions
src/node/src/client.js
with
18 additions
and
2 deletions
src/node/ext/call.cc
+
8
−
0
View file @
8d18c6ed
...
...
@@ -721,6 +721,14 @@ NAN_METHOD(Call::StartBatch) {
}
Local
<
Function
>
callback_func
=
info
[
1
].
As
<
Function
>
();
Call
*
call
=
ObjectWrap
::
Unwrap
<
Call
>
(
info
.
This
());
if
(
call
->
wrapped_call
==
NULL
)
{
/* This implies that the call has completed and has been destroyed. To emulate
* previous behavior, we should call the callback immediately with an error,
* as though the batch had failed in core */
Local
<
Value
>
argv
[]
=
{
Nan
::
Error
(
"The async function failed because the call has completed"
)};
Nan
::
Call
(
callback_func
,
Nan
::
New
<
Object
>
(),
1
,
argv
);
return
;
}
Local
<
Object
>
obj
=
Nan
::
To
<
Object
>
(
info
[
0
]).
ToLocalChecked
();
Local
<
Array
>
keys
=
Nan
::
GetOwnPropertyNames
(
obj
).
ToLocalChecked
();
size_t
nops
=
keys
->
Length
();
...
...
This diff is collapsed.
Click to expand it.
src/node/src/client.js
+
10
−
2
View file @
8d18c6ed
...
...
@@ -100,6 +100,12 @@ function _write(chunk, encoding, callback) {
/* jshint validthis: true */
var
batch
=
{};
var
message
;
var
self
=
this
;
if
(
this
.
writeFailed
)
{
/* Once a write fails, just call the callback immediately to let the caller
flush any pending writes. */
callback
();
}
try
{
message
=
this
.
serialize
(
chunk
);
}
catch
(
e
)
{
...
...
@@ -119,8 +125,10 @@ function _write(chunk, encoding, callback) {
batch
[
grpc
.
opType
.
SEND_MESSAGE
]
=
message
;
this
.
call
.
startBatch
(
batch
,
function
(
err
,
event
)
{
if
(
err
)
{
// Something has gone wrong. Stop writing by failing to call callback
return
;
/* Assume that the call is complete and that writing failed because a
status was received. In that case, set a flag to discard all future
writes */
self
.
writeFailed
=
true
;
}
callback
();
});
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment