~emersion/public-inbox

tlstunnel: Only bump fd limits on unix OSes v1 SUPERSEDED

Tom Lebreux: 1
 Only bump fd limits on unix OSes

 3 files changed, 29 insertions(+), 12 deletions(-)
#1210204 .build.yml success
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~emersion/public-inbox/patches/51518/mbox | git am -3
Learn more about email & git

[PATCH tlstunnel] Only bump fd limits on unix OSes Export this patch

---
Full disclosure, this is to make it work on Windows. I understand if
you're not willing to accept this patch for that reason.

My use case is running Ollama which listens to localhost with tlstunnel in
front. I then have caddy in a separate VLAN that connects to the
tlstunnel with client auth (from the other patch).

	[user] ---> [caddy] <---mtls---> [tlstunnel] <---localhost---> [ollama]

 cmd/tlstunnel/main.go       | 12 ------------
 cmd/tlstunnel/tune_other.go |  8 ++++++++
 cmd/tlstunnel/tune_unix.go  | 21 +++++++++++++++++++++
 3 files changed, 29 insertions(+), 12 deletions(-)
 create mode 100644 cmd/tlstunnel/tune_other.go
 create mode 100644 cmd/tlstunnel/tune_unix.go

diff --git a/cmd/tlstunnel/main.go b/cmd/tlstunnel/main.go
index 1adcac317619..687a822b8331 100644
--- a/cmd/tlstunnel/main.go
+++ b/cmd/tlstunnel/main.go
@@ -51,18 +51,6 @@ func newServer() (*tlstunnel.Server, error) {
	return srv, nil
}

func bumpOpenedFileLimit() error {
	var rlimit syscall.Rlimit
	if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlimit); err != nil {
		return fmt.Errorf("failed to get RLIMIT_NOFILE: %v", err)
	}
	rlimit.Cur = rlimit.Max
	if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlimit); err != nil {
		return fmt.Errorf("failed to set RLIMIT_NOFILE: %v", err)
	}
	return nil
}

func main() {
	flag.StringVar(&configPath, "config", configPath, "path to configuration file")
	flag.BoolVar(&debug, "debug", false, "enable debug logging")
diff --git a/cmd/tlstunnel/tune_other.go b/cmd/tlstunnel/tune_other.go
new file mode 100644
index 000000000000..074ee49ae5a3
--- /dev/null
+++ b/cmd/tlstunnel/tune_other.go
@@ -0,0 +1,8 @@
//go:build !unix
// +build !unix

package main

func bumpOpenedFileLimit() error {
	return nil
}
diff --git a/cmd/tlstunnel/tune_unix.go b/cmd/tlstunnel/tune_unix.go
new file mode 100644
index 000000000000..0a64d831925a
--- /dev/null
+++ b/cmd/tlstunnel/tune_unix.go
@@ -0,0 +1,21 @@
//go:build unix
// +build unix

package main

import (
	"fmt"
	"syscall"
)

func bumpOpenedFileLimit() error {
	var rlimit syscall.Rlimit
	if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlimit); err != nil {
		return fmt.Errorf("failed to get RLIMIT_NOFILE: %v", err)
	}
	rlimit.Cur = rlimit.Max
	if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlimit); err != nil {
		return fmt.Errorf("failed to set RLIMIT_NOFILE: %v", err)
	}
	return nil
}
-- 
2.44.0
tlstunnel/patches/.build.yml: SUCCESS in 27s

[Only bump fd limits on unix OSes][0] from [Tom Lebreux][1]

[0]: https://lists.sr.ht/~emersion/public-inbox/patches/51518
[1]: mailto:me@tomlebreux.com

✓ #1210204 SUCCESS tlstunnel/patches/.build.yml https://builds.sr.ht/~emersion/job/1210204
To be honest, this is now something that the Go runtime does
automatically [1] so should no longer be needed with Go 1.19 and later.
Maybe we should just drop it?

[1]: https://github.com/golang/go/commit/8427429c592588af8c49522c76b3e0e0e335d270