mirror of
https://github.com/mudler/LocalAI.git
synced 2026-10-09 22:54:42 -04:00
test(cli): transfer socket descriptor ownership (#12465)
Duplicate the socket descriptor before handing it to the activation helper. Close the original file to prevent its finalizer from closing a reused coverage descriptor after the helper closes its own file wrapper. Assisted-by: Codex:gpt-6 Co-authored-by: localai-org-maint-bot <306269227+localai-org-maint-bot@users.noreply.github.com>
This commit is contained in:
1 parent
d90f703bd9
commit
4a72b2ac2e
1 file changed
+9
-1
@@ -7,6 +7,8 @@ import (
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
@@ -53,7 +55,13 @@ var _ = Describe("systemdActivatedListeners", func() {
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(original.Close()).To(Succeed())
|
||||
|
||||
listeners, err := listenersFromSystemdFDs(int(file.Fd()), 1)
|
||||
// The activation helper takes ownership of a raw descriptor. Give it a
|
||||
// duplicate so file's finalizer cannot close a later user of that descriptor.
|
||||
fd, err := unix.Dup(int(file.Fd()))
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(file.Close()).To(Succeed())
|
||||
|
||||
listeners, err := listenersFromSystemdFDs(fd, 1)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(listeners).To(HaveLen(1))
|
||||
DeferCleanup(listeners[0].Close)
|
||||
|
||||
Reference in new issue
Block a user