Skip to content

Commit

Permalink
fix(node): fixed stopped checking (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlangzi authored Mar 19, 2024
1 parent 859cd85 commit 0f2a8d1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion mutext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestLock(t *testing.T) {
{
name: "lock_should_work",
run: func(r *require.Assertions) {
m := New("lock_should_work", "wallet", "lock_should_work", WithPeers(peers...), WithTTL(10*time.Second))
m := New("lock_should_work", "wallet", "lock_should_work", WithPeers(peers...), WithTTL(10*time.Second), WithTimeout(5*time.Second))
err := m.Lock(context.TODO())
r.NoError(err)
r.Equal(10*time.Second, m.lease.TTL.Duration())
Expand Down
16 changes: 8 additions & 8 deletions node_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,20 @@ func (n *Node) waitRequest() {
for {
conn, err := n.listener.Accept()

if err == nil {

if n.isStopped() {
return
}

go n.server.ServeConn(conn)
if n.isStopped() {
return
}

} else {
if err != nil {
// listener is closed
if errors.Is(err, net.ErrClosed) {
return
}

n.logger.Warn("dlm: wait request", slog.String("err", err.Error()), slog.String("addr", n.addr))
continue
}

go n.server.ServeConn(conn)
}
}
3 changes: 2 additions & 1 deletion node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dlm

import (
"database/sql"
"log/slog"
"net"
"os"
"strconv"
Expand Down Expand Up @@ -50,7 +51,7 @@ func TestLease(t *testing.T) {
db, clean, err := createSqlite3()
require.NoError(t, err)
defer clean()
n := NewNode(getFreeAddr(), sqle.Open(db))
n := NewNode(getFreeAddr(), sqle.Open(db), WithLogger(slog.Default()))
err = n.Start()
require.NoError(t, err)
defer n.Stop()
Expand Down

0 comments on commit 0f2a8d1

Please sign in to comment.