Skip to content

Commit

Permalink
Merge pull request #569 from rgooch/master
Browse files Browse the repository at this point in the history
Fix some FD and goroutine leaks.
  • Loading branch information
rgooch committed Mar 5, 2019
2 parents d57f6fe + ca4dcab commit 70c8095
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
5 changes: 3 additions & 2 deletions hypervisor/manager/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ func (m *Manager) createVm(conn *srpc.Conn, decoder srpc.Decoder,
ownerUsers := make([]string, 1, len(request.OwnerUsers)+1)
ownerUsers[0] = conn.Username()
if ownerUsers[0] == "" {
return errors.New("no authentication data")
return sendError(conn, encoder, errors.New("no authentication data"))
}
ownerUsers = append(ownerUsers, request.OwnerUsers...)
vm, err := m.allocateVm(request, conn.GetAuthInformation())
Expand Down Expand Up @@ -2167,6 +2167,8 @@ func (vm *vmInfoType) processMonitorResponses(monitorSock net.Conn) {
io.Copy(ioutil.Discard, monitorSock) // Read all and drop.
vm.mutex.Lock()
defer vm.mutex.Unlock()
close(vm.commandChannel)
vm.commandChannel = nil
switch vm.State {
case proto.StateStarting:
return
Expand All @@ -2190,7 +2192,6 @@ func (vm *vmInfoType) processMonitorResponses(monitorSock net.Conn) {
default:
vm.logger.Println("unknown state: " + vm.State.String())
}
close(vm.commandChannel)
}

func (vm *vmInfoType) rootLabel() string {
Expand Down
11 changes: 9 additions & 2 deletions hypervisor/metadatad/daemons.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os/exec"
"runtime"
"strconv"
"time"

"github.com/Symantec/Dominator/lib/log"
"github.com/Symantec/Dominator/lib/log/prefixlogger"
Expand All @@ -22,6 +23,12 @@ type statusType struct {
err error
}

func httpServe(listener net.Listener, handler http.Handler,
idleTimeout time.Duration) error {
httpServer := &http.Server{Handler: handler, IdleTimeout: idleTimeout}
return httpServer.Serve(listener)
}

func (s *server) startServer() error {
cmd := exec.Command("ebtables", "-t", "nat", "-F")
if output, err := cmd.CombinedOutput(); err != nil {
Expand Down Expand Up @@ -116,8 +123,8 @@ func (s *server) createNamespace(startChannel <-chan struct{},
}
statusChannel <- statusType{namespaceFd: namespaceFd, threadId: threadId}
logger.Printf("starting metadata server in thread: %d\n", threadId)
go http.Serve(hypervisorListener, nil)
http.Serve(metadataListener, s)
go httpServe(hypervisorListener, nil, time.Second*5)
httpServe(metadataListener, s, time.Second*5)
}

func createInterface(bridge net.Interface, threadId int,
Expand Down
6 changes: 3 additions & 3 deletions hypervisor/rpcd/probeVmPort.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ func (t *srpcType) ProbeVmPort(conn *srpc.Conn,
ok, err := probeVmPort(
fmt.Sprintf("%s:%d", request.IpAddress, request.PortNumber),
request.Timeout)
response := hypervisor.ProbeVmPortResponse{ok, errors.ErrorToString(err)}
*reply = response
*reply = hypervisor.ProbeVmPortResponse{ok, errors.ErrorToString(err)}
return nil
}

Expand All @@ -48,9 +47,10 @@ func probeVmPort(addr string, timeout time.Duration) (bool, error) {

func probeOnce(addr string, okChannel chan<- struct{}) {
if conn, err := net.DialTimeout("tcp", addr, time.Second); err == nil {
conn.Close()
select {
case okChannel <- struct{}{}:
default:
}
conn.Close()
}
}
2 changes: 0 additions & 2 deletions lib/filesystem/util/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"io"
"os"
"text/template"

"github.com/Symantec/Dominator/lib/filesystem"
"github.com/Symantec/Dominator/lib/log"
Expand All @@ -19,7 +18,6 @@ type BootInfoType struct {
KernelImageDirent *filesystem.DirectoryEntry
KernelImageFile string
KernelOptions string
grubTemplate *template.Template
}

type ComputedFile struct {
Expand Down
9 changes: 3 additions & 6 deletions lib/filesystem/util/writeRaw.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const (
var (
mutex sync.Mutex
defaultMkfsFeatures map[string]struct{} // Key: feature name.
grubTemplate = template.Must(template.New("grub").Parse(
grubTemplateString))
)

func checkIfPartition(device string) (bool, error) {
Expand Down Expand Up @@ -381,11 +383,6 @@ func getBootInfo(fs *filesystem.FileSystem, rootLabel string,
bootInfo.KernelImageFile = "/boot/" + dirent.Name
}
}
bootInfo.grubTemplate, err = template.New("grub").Parse(
grubTemplateString)
if err != nil {
return nil, err
}
return bootInfo, nil
}

Expand Down Expand Up @@ -436,7 +433,7 @@ func (bootInfo *BootInfoType) writeGrubConfig(filename string) error {
return fmt.Errorf("error creating GRUB config file: %s", err)
}
defer file.Close()
if err := bootInfo.grubTemplate.Execute(file, bootInfo); err != nil {
if err := grubTemplate.Execute(file, bootInfo); err != nil {
return err
}
return file.Close()
Expand Down
3 changes: 2 additions & 1 deletion lib/objectserver/cachingreader/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func saveObject(filename string,
if size, reader, err := objectsReader.NextObject(); err != nil {
return err
} else {
defer reader.Close()
err := fsutil.CopyToFile(filename, privateFilePerms, reader, size)
if err == nil {
return nil
Expand Down Expand Up @@ -212,7 +213,7 @@ func timeoutFunction(f func(), timeout time.Duration) {
f()
return
}
completionChannel := make(chan struct{})
completionChannel := make(chan struct{}, 1)
go func() {
f()
completionChannel <- struct{}{}
Expand Down

0 comments on commit 70c8095

Please sign in to comment.