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
a9bd9433
Commit
a9bd9433
authored
8 years ago
by
Mark D. Roth
Browse files
Options
Downloads
Patches
Plain Diff
Fix unref-while-lock-held bug. Only shut down handshaker if in progress.
parent
06104341
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/core/lib/channel/handshaker.c
+22
-13
22 additions, 13 deletions
src/core/lib/channel/handshaker.c
with
22 additions
and
13 deletions
src/core/lib/channel/handshaker.c
+
22
−
13
View file @
a9bd9433
...
@@ -141,7 +141,8 @@ void grpc_handshake_manager_destroy(grpc_exec_ctx* exec_ctx,
...
@@ -141,7 +141,8 @@ void grpc_handshake_manager_destroy(grpc_exec_ctx* exec_ctx,
void
grpc_handshake_manager_shutdown
(
grpc_exec_ctx
*
exec_ctx
,
void
grpc_handshake_manager_shutdown
(
grpc_exec_ctx
*
exec_ctx
,
grpc_handshake_manager
*
mgr
)
{
grpc_handshake_manager
*
mgr
)
{
gpr_mu_lock
(
&
mgr
->
mu
);
gpr_mu_lock
(
&
mgr
->
mu
);
if
(
mgr
->
index
>
0
)
{
// Shutdown the handshaker that's currently in progress, if any.
if
(
mgr
->
index
>
0
&&
mgr
->
index
<=
mgr
->
count
)
{
grpc_handshaker_shutdown
(
exec_ctx
,
mgr
->
handshakers
[
mgr
->
index
-
1
]);
grpc_handshaker_shutdown
(
exec_ctx
,
mgr
->
handshakers
[
mgr
->
index
-
1
]);
}
}
gpr_mu_unlock
(
&
mgr
->
mu
);
gpr_mu_unlock
(
&
mgr
->
mu
);
...
@@ -149,28 +150,27 @@ void grpc_handshake_manager_shutdown(grpc_exec_ctx* exec_ctx,
...
@@ -149,28 +150,27 @@ void grpc_handshake_manager_shutdown(grpc_exec_ctx* exec_ctx,
// Helper function to call either the next handshaker or the
// Helper function to call either the next handshaker or the
// on_handshake_done callback.
// on_handshake_done callback.
static
void
call_next_handshaker_locked
(
grpc_exec_ctx
*
exec_ctx
,
// Returns true if we've scheduled the on_handshake_done callback.
static
bool
call_next_handshaker_locked
(
grpc_exec_ctx
*
exec_ctx
,
grpc_handshake_manager
*
mgr
,
grpc_handshake_manager
*
mgr
,
grpc_error
*
error
)
{
grpc_error
*
error
)
{
GPR_ASSERT
(
mgr
->
index
<=
mgr
->
count
);
GPR_ASSERT
(
mgr
->
index
<=
mgr
->
count
);
// If we got an error or we've finished the last handshaker, invoke
// If we got an error or we've finished the last handshaker, invoke
// the on_handshake_done callback. Otherwise, call the next handshaker.
// the on_handshake_done callback. Otherwise, call the next handshaker.
bool
done
=
false
;
if
(
error
!=
GRPC_ERROR_NONE
||
mgr
->
index
==
mgr
->
count
)
{
if
(
error
!=
GRPC_ERROR_NONE
||
mgr
->
index
==
mgr
->
count
)
{
// Cancel deadline timer, since we're invoking the on_handshake_done
// Cancel deadline timer, since we're invoking the on_handshake_done
// callback now.
// callback now.
grpc_timer_cancel
(
exec_ctx
,
&
mgr
->
deadline_timer
);
grpc_timer_cancel
(
exec_ctx
,
&
mgr
->
deadline_timer
);
grpc_exec_ctx_sched
(
exec_ctx
,
&
mgr
->
on_handshake_done
,
error
,
NULL
);
grpc_exec_ctx_sched
(
exec_ctx
,
&
mgr
->
on_handshake_done
,
error
,
NULL
);
// Since we're invoking the final callback, we won't be coming back
done
=
true
;
// to this function, so we can release our reference to the
}
else
{
// handshake manager.
grpc_handshaker_do_handshake
(
exec_ctx
,
mgr
->
handshakers
[
mgr
->
index
],
grpc_handshake_manager_unref
(
exec_ctx
,
mgr
);
mgr
->
acceptor
,
&
mgr
->
call_next_handshaker
,
return
;
&
mgr
->
args
)
;
}
}
// Call the next handshaker.
grpc_handshaker_do_handshake
(
exec_ctx
,
mgr
->
handshakers
[
mgr
->
index
],
mgr
->
acceptor
,
&
mgr
->
call_next_handshaker
,
&
mgr
->
args
);
++
mgr
->
index
;
++
mgr
->
index
;
return
done
;
}
}
// A function used as the handshaker-done callback when chaining
// A function used as the handshaker-done callback when chaining
...
@@ -179,8 +179,14 @@ static void call_next_handshaker(grpc_exec_ctx* exec_ctx, void* arg,
...
@@ -179,8 +179,14 @@ static void call_next_handshaker(grpc_exec_ctx* exec_ctx, void* arg,
grpc_error
*
error
)
{
grpc_error
*
error
)
{
grpc_handshake_manager
*
mgr
=
arg
;
grpc_handshake_manager
*
mgr
=
arg
;
gpr_mu_lock
(
&
mgr
->
mu
);
gpr_mu_lock
(
&
mgr
->
mu
);
call_next_handshaker_locked
(
exec_ctx
,
mgr
,
GRPC_ERROR_REF
(
error
));
bool
done
=
call_next_handshaker_locked
(
exec_ctx
,
mgr
,
GRPC_ERROR_REF
(
error
));
gpr_mu_unlock
(
&
mgr
->
mu
);
gpr_mu_unlock
(
&
mgr
->
mu
);
// If we're invoked the final callback, we won't be coming back
// to this function, so we can release our reference to the
// handshake manager.
if
(
done
)
{
grpc_handshake_manager_unref
(
exec_ctx
,
mgr
);
}
}
}
// Callback invoked when deadline is exceeded.
// Callback invoked when deadline is exceeded.
...
@@ -217,6 +223,9 @@ void grpc_handshake_manager_do_handshake(
...
@@ -217,6 +223,9 @@ void grpc_handshake_manager_do_handshake(
on_timeout
,
mgr
,
gpr_now
(
GPR_CLOCK_MONOTONIC
));
on_timeout
,
mgr
,
gpr_now
(
GPR_CLOCK_MONOTONIC
));
// Start first handshaker, which also owns a ref.
// Start first handshaker, which also owns a ref.
gpr_ref
(
&
mgr
->
refs
);
gpr_ref
(
&
mgr
->
refs
);
call_next_handshaker_locked
(
exec_ctx
,
mgr
,
GRPC_ERROR_NONE
);
bool
done
=
call_next_handshaker_locked
(
exec_ctx
,
mgr
,
GRPC_ERROR_NONE
);
gpr_mu_unlock
(
&
mgr
->
mu
);
gpr_mu_unlock
(
&
mgr
->
mu
);
if
(
done
)
{
grpc_handshake_manager_unref
(
exec_ctx
,
mgr
);
}
}
}
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