Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
ad201cd1
Unverified
Commit
ad201cd1
authored
Jun 04, 2021
by
aloknerurkar
Committed by
GitHub
Jun 04, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: shutdown only once (#1912)
parent
01a587d8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
1 deletion
+13
-1
node.go
pkg/node/node.go
+13
-1
No files found.
pkg/node/node.go
View file @
ad201cd1
...
@@ -103,6 +103,8 @@ type Bee struct {
...
@@ -103,6 +103,8 @@ type Bee struct {
recoveryHandleCleanup
func
()
recoveryHandleCleanup
func
()
listenerCloser
io
.
Closer
listenerCloser
io
.
Closer
postageServiceCloser
io
.
Closer
postageServiceCloser
io
.
Closer
shutdownInProgress
bool
shutdownMutex
sync
.
Mutex
}
}
type
Options
struct
{
type
Options
struct
{
...
@@ -707,6 +709,15 @@ func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey,
...
@@ -707,6 +709,15 @@ func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey,
func
(
b
*
Bee
)
Shutdown
(
ctx
context
.
Context
)
error
{
func
(
b
*
Bee
)
Shutdown
(
ctx
context
.
Context
)
error
{
var
mErr
error
var
mErr
error
// if a shutdown is already in process, return here
b
.
shutdownMutex
.
Lock
()
if
b
.
shutdownInProgress
{
b
.
shutdownMutex
.
Unlock
()
return
ErrShutdownInProgress
}
b
.
shutdownInProgress
=
true
b
.
shutdownMutex
.
Unlock
()
// halt kademlia while shutting down other
// halt kademlia while shutting down other
// components.
// components.
b
.
topologyHalter
.
Halt
()
b
.
topologyHalter
.
Halt
()
...
@@ -714,7 +725,6 @@ func (b *Bee) Shutdown(ctx context.Context) error {
...
@@ -714,7 +725,6 @@ func (b *Bee) Shutdown(ctx context.Context) error {
// halt p2p layer from accepting new connections
// halt p2p layer from accepting new connections
// while shutting down other components
// while shutting down other components
b
.
p2pHalter
.
Halt
()
b
.
p2pHalter
.
Halt
()
// tryClose is a convenient closure which decrease
// tryClose is a convenient closure which decrease
// repetitive io.Closer tryClose procedure.
// repetitive io.Closer tryClose procedure.
tryClose
:=
func
(
c
io
.
Closer
,
errMsg
string
)
{
tryClose
:=
func
(
c
io
.
Closer
,
errMsg
string
)
{
...
@@ -851,6 +861,8 @@ type pidKiller struct {
...
@@ -851,6 +861,8 @@ type pidKiller struct {
node
*
Bee
node
*
Bee
}
}
var
ErrShutdownInProgress
error
=
errors
.
New
(
"shutdown in progress"
)
func
(
p
*
pidKiller
)
Shutdown
(
ctx
context
.
Context
)
error
{
func
(
p
*
pidKiller
)
Shutdown
(
ctx
context
.
Context
)
error
{
err
:=
p
.
node
.
Shutdown
(
ctx
)
err
:=
p
.
node
.
Shutdown
(
ctx
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment