Commit 78905166 authored by ale's avatar ale

Update dependencies (go-common/unix)

parent 17891195
Pipeline #2668 passed with stages
in 2 minutes and 12 seconds
......@@ -2,6 +2,7 @@ package unix
import (
"bufio"
"container/list"
"context"
"errors"
"io"
......@@ -32,6 +33,11 @@ type SocketServer struct {
closing atomic.Value
wg sync.WaitGroup
handler Handler
// Keep track of active connections so we can shut them down
// on Close.
connMx sync.Mutex
conns list.List
}
func newServer(l net.Listener, lock *flock.Flock, h Handler) *SocketServer {
......@@ -99,7 +105,18 @@ func NewSystemdSocketServer(h Handler) (*SocketServer, error) {
// Waits for active connections to terminate before returning.
func (s *SocketServer) Close() {
s.closing.Store(true)
// Close the listener to stop incoming connections.
s.l.Close() // nolint
// Close all active connections (this will return an error to
// the client if the connection is not idle).
s.connMx.Lock()
for el := s.conns.Front(); el != nil; el = el.Next() {
el.Value.(net.Conn).Close() // nolint
}
s.connMx.Unlock()
s.wg.Wait()
if s.lock != nil {
s.lock.Unlock() // nolint
......@@ -120,10 +137,21 @@ func (s *SocketServer) Serve() error {
}
return err
}
s.wg.Add(1)
s.connMx.Lock()
connEl := s.conns.PushBack(conn)
s.connMx.Unlock()
go func() {
s.handler.ServeConnection(conn)
conn.Close() // nolint
if !s.isClosing() {
s.connMx.Lock()
s.conns.Remove(connEl)
s.connMx.Unlock()
}
s.wg.Done()
}()
}
......
......@@ -39,10 +39,10 @@
"revisionTime": "2019-02-17T09:01:06Z"
},
{
"checksumSHA1": "R18oCPkWjuPqDxPgKvG1KhiSJns=",
"checksumSHA1": "jRc0JfRUtCr3xxkgwRDVppsSnl0=",
"path": "git.autistici.org/ai3/go-common/unix",
"revision": "2934fd63c275d37b0fe60afabb484a251662bd49",
"revisionTime": "2019-02-17T09:01:06Z"
"revision": "b4364e842290fdecd412056674b471af77663757",
"revisionTime": "2019-04-03T06:59:52Z"
},
{
"checksumSHA1": "J0QeD9LVccFOejgPKa0td8JD0rY=",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment