diff --git a/mutext_test.go b/mutext_test.go index 504cb46..eec0874 100644 --- a/mutext_test.go +++ b/mutext_test.go @@ -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()) diff --git a/node_svc.go b/node_svc.go index 4b7fb27..b56bd88 100644 --- a/node_svc.go +++ b/node_svc.go @@ -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) } } diff --git a/node_test.go b/node_test.go index 4705c43..edff869 100644 --- a/node_test.go +++ b/node_test.go @@ -2,6 +2,7 @@ package dlm import ( "database/sql" + "log/slog" "net" "os" "strconv" @@ -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()