Instead of updating the configuration, we configure a new Server instance and
then migrate Listeners that still exist to it. Open client connections are
left completely untouched.
Closes https://todo.sr.ht/~emersion/tlstunnel/1
---
This basically works, but there's two TODOs that I'd like feedback on:
The listener migration is not concurrency-safe, but putting a lock
around it doesn't seem like a nice solution to me.
Hm. It doesn't seem like using a channel would be a lot nicer. This problem
makes me think of [1], but not sure it'd be a lot nicer than a mutex.
[1]: https://golang.org/pkg/sync/atomic/#example_Value_config
I can see where you're coming from, but I wonder if it really makes sense. For
some use-cases (e.g. HTTP, SMTP, maybe IMAP), you don't want to interrupt an
open connection, and connections aren't long-lived. For some other use-cases
(WebSockets, IMAP with IDLE, IRC) connections are long-lived and
clients/servers won't close them in a timely manner.
Is there a way to design shutdown so that both use-cases are accounted for?
Maybe wait for opened connections on the first SIGINT, and force-close on the
second one? Maybe have a timeout? Something else? In any case, I'm fine with
deferring this for now.
+ switch sig {+ case syscall.SIGINT:+ case syscall.SIGTERM:+ srv.Stop()+ return+ case syscall.SIGHUP:+ log.Print("caught SIGHUP, reloading config")+ newSrv := newServer()
+ } else if err != nil { return fmt.Errorf("failed to accept connection: %v", err)
}
@@ -265,7 +338,7 @@ func authorityTLV(name string) proxyproto.TLV {
func alpnTLV(proto string) proxyproto.TLV {
return proxyproto.TLV{
- Type: proxyproto.PP2_TYPE_ALPN,+ Type: proxyproto.PP2_TYPE_ALPN, Value: []byte(proto),
}
}
diff --git a/tlstunnel.1.scd b/tlstunnel.1.scd
index 30ee269..b4c409a 100644
--- a/tlstunnel.1.scd+++ b/tlstunnel.1.scd
@@ -27,6 +27,8 @@ The config file has one directive per line. Directives have a name, followed
by parameters separated by space characters. Directives may have children in
blocks delimited by "{" and "}". Lines beginning with "#" are comments.
+tlstunnel will reload the config file when it receives the HUP signal.+Example:
```
--
2.29.2