Fix awg-ctrl hanging on the torrent flag; log out on an expired session
The torrent flag was read inside loops over users rows (users/stats, peers, metrics) and each read queried the config table. SQLite has a single connection here, so the nested query waited for it forever: the first stats request or Prometheus scrape locked awg-ctrl for good, and the panel showed no users and timed out. - the block setting is kept in memory (loaded at start, updated on save), so the flag never touches the database - the set of flagged IPs is taken once before the query, not per row - regression test: collectMetrics must finish with users in the table Panel: a 401 from the panel itself (its JWT not accepted) now returns to the login screen; a 401 relayed from a node's awg-ctrl does not.
This commit is contained in:
@@ -129,6 +129,7 @@ func (s *Server) collectMetrics() (*metricsBody, error) {
|
||||
if st.Up {
|
||||
stats = s.getPeersData()
|
||||
}
|
||||
torrent := s.torrent.SeenSet() // до запроса: внутри цикла по строкам — ни базы, ни nft
|
||||
rows, err := s.db.Query("SELECT name, ip, pub_key FROM users WHERE vpn_key != ''")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -141,7 +142,7 @@ func (s *Server) collectMetrics() (*metricsBody, error) {
|
||||
return nil, err
|
||||
}
|
||||
ps := stats[pub]
|
||||
b.List = append(b.List, metricsPeer{"user", n, ip, ps.Online, orZero(ps.Rx), orZero(ps.Tx), s.shaping.PriorityOf(ip), s.torrent.Seen(ip)})
|
||||
b.List = append(b.List, metricsPeer{"user", n, ip, ps.Online, orZero(ps.Rx), orZero(ps.Tx), s.shaping.PriorityOf(ip), torrent[ip]})
|
||||
}
|
||||
rows.Close()
|
||||
devs, err := s.peersAll()
|
||||
@@ -150,7 +151,7 @@ func (s *Server) collectMetrics() (*metricsBody, error) {
|
||||
}
|
||||
for _, p := range devs {
|
||||
ps := stats[p.PubKey]
|
||||
b.List = append(b.List, metricsPeer{"device", "", p.IP, ps.Online, orZero(ps.Rx), orZero(ps.Tx), s.shaping.PriorityOf(p.IP), s.torrent.Seen(p.IP)})
|
||||
b.List = append(b.List, metricsPeer{"device", "", p.IP, ps.Online, orZero(ps.Rx), orZero(ps.Tx), s.shaping.PriorityOf(p.IP), torrent[p.IP]})
|
||||
}
|
||||
b.Peers.Total = st.Peers
|
||||
for _, ps := range stats {
|
||||
|
||||
Reference in New Issue
Block a user