releaseFileDB decrements the ref count for a user's shared DB. When the last reference is released, the DB is closed and removed from the pool.
(username string)
| 811 | // DrainUserConnections requests a clean close of every PostgreSQL connection |
| 812 | // for one org user. It is used when a project reader's credentials or access |
| 813 | // policy changes so an established connection cannot retain stale access. |
| 814 | func (s *Server) DrainUserConnections(orgID, username string) int { |
| 815 | return s.drainConnections(func(c *clientConn) bool { |
| 816 | return c.orgID == orgID && c.username == username |
| 817 | }) |
| 818 | } |
| 819 | |
| 820 | func (s *Server) drainConnections(matches func(*clientConn) bool) int { |
| 821 | s.connsMu.RLock() |
| 822 | conns := make([]*clientConn, 0) |
| 823 | for _, c := range s.conns { |
| 824 | if c != nil && matches(c) { |
| 825 | conns = append(conns, c) |
| 826 | } |
| 827 | } |
| 828 | s.connsMu.RUnlock() |
| 829 | |
| 830 | for _, c := range conns { |
| 831 | c.drainRequested.Store(true) |
| 832 | if c.conn != nil && c.idleRead.Load() { |