Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gRPC
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
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
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Partitio
Lab
gRPC
Commits
af25e091
Commit
af25e091
authored
5 years ago
by
Adphi
Browse files
Options
Downloads
Patches
Plain Diff
fix graceful stop
parent
ac9a81d3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
service/service.go
+10
-6
10 additions, 6 deletions
service/service.go
with
10 additions
and
6 deletions
service/service.go
+
10
−
6
View file @
af25e091
package
service
import
(
"context"
"net"
"os"
"sync"
...
...
@@ -27,11 +28,12 @@ func New(opts ...Option) (Service, error) {
}
type
service
struct
{
cmd
*
cobra
.
Command
opts
*
options
server
*
grpc
.
Server
list
net
.
Listener
mu
sync
.
Mutex
cmd
*
cobra
.
Command
opts
*
options
cancel
context
.
CancelFunc
server
*
grpc
.
Server
list
net
.
Listener
mu
sync
.
Mutex
running
bool
}
...
...
@@ -49,6 +51,7 @@ func newService(opts ...Option) (*service, error) {
if
s
.
opts
.
error
!=
nil
{
return
nil
,
s
.
opts
.
error
}
s
.
opts
.
ctx
,
s
.
cancel
=
context
.
WithCancel
(
s
.
opts
.
ctx
)
go
func
()
{
for
{
select
{
...
...
@@ -117,7 +120,7 @@ func (s *service) run() error {
}
}
s
.
mu
.
Unlock
()
return
<-
errs
return
<-
errs
}
func
(
s
*
service
)
Start
()
error
{
...
...
@@ -136,6 +139,7 @@ func (s *service) Stop() error {
}
}
s
.
server
.
GracefulStop
()
s
.
cancel
()
s
.
running
=
false
for
i
:=
range
s
.
opts
.
afterStop
{
if
err
:=
s
.
opts
.
afterStop
[
i
]();
err
!=
nil
{
...
...
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