Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clamd connections are not being closed #2

Closed
jblackman opened this issue Jul 21, 2015 · 1 comment
Closed

Clamd connections are not being closed #2

jblackman opened this issue Jul 21, 2015 · 1 comment

Comments

@jblackman
Copy link
Contributor

I have encountered an issue in this otherwise excellent package, It appears that the connection to clamd is not being closed. I am running this on a Debian jessie system, with go v1.4.2. It's pretty easy to reproduce, just run the example from the README in a loop a thousand times, pause, and check the open files (e.g. using lsof).

package main

import (
    "bufio"
    "bytes"
    "fmt"
    clamd "github.com/dutchcoders/go-clamd"
    "os"
)

func main() {
    for i := 0; i < 1000; i++ {
        sendRequest("/var/run/clamav/clamd.ctl", clamd.EICAR)
    }
    fmt.Println("Hit <enter>")
    bufio.NewReader(os.Stdin).ReadString('\n')
}

func sendRequest(clamav string, content []byte) {
    c := clamd.NewClamd(clamav)

    reader := bytes.NewReader(content)
    response, err := c.ScanStream(reader)

    for s := range response {
        fmt.Printf("%v %v\n", s, err)
    }
}

Looking at the code, it appears that line clamd.go:282 is not firing:

wg.Wait()

On a whim, I changed the return value of conn.go:76 to return a pointer to the WaitGroup, on the hunch that the return value is being copied and so will never fire. This works.

func (c *CLAMDConn) readResponse() (chan string, *sync.WaitGroup, error) {
...
    return ch, &wg, nil

Do you agree with my diagnosis?

@kzsnow
Copy link

kzsnow commented Jul 21, 2015

I just ran into the same issue with unclosed sockets. Your suggestion did fix it, thanks for the diagnosis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants