dutchcoders/transfer.sh · error

clamav scan timeout

Error message

clamav scan timeout

What it means

performScan wraps the ClamAV clamd INSTREAM virus scan in a 60-second timeout implemented via select/time.After. If the clamd daemon neither returns a response nor an error within 60 seconds, the scan is abandoned and this error is returned to the upload handlers (scan/post/put). It indicates the antivirus backend is unresponsive or the file scan is taking too long.

Source

Thrown at server/clamav.go:100

	errCh := make(chan error)
	go func(responseCh chan chan *clamd.ScanResult, errCh chan error) {
		response, err := c.ScanFile(path)
		if err != nil {
			errCh <- err
			return
		}

		responseCh <- response
	}(responseCh, errCh)

	select {
	case err := <-errCh:
		return "", err
	case response := <-responseCh:
		st := <-response
		return st.Status, nil
	case <-time.After(time.Second * 60):
		return "", errors.New("clamav scan timeout")
	}
}

View on GitHub (pinned to c37bfd9579)

Solutions

  1. Check the clamd daemon is running and responsive (clamd scan / PING on the configured host:port) and restart it if hung.
  2. Reduce upload file size limits or exclude very large files from AV scanning.
  3. Increase capacity: run clamd closer to the server (unix socket / same host) or scale concurrent clamd instances.
  4. Patch the 60s constant in server/clamav.go to a configurable, larger timeout for large-file workloads.

Example fix

// before
case <-time.After(time.Second * 60):
	return "", errors.New("clamav scan timeout")
// after
timeout := s.avScanTimeout // configurable, e.g. 5 * time.Minute
case <-time.After(timeout):
	return "", fmt.Errorf("clamav scan timeout after %s", timeout)
Defensive patterns

Strategy: retry

Validate before calling

// before uploading, verify clamd is reachable
timeout 5 bash -c 'cat < /dev/null > /dev/tcp/clamav-host/3310' || echo "clamd unreachable"

Try / catch

if _, err := upload(f); err != nil {
	if strings.Contains(err.Error(), "clamav scan timeout") {
		// back off and retry once, or skip AV scanning for this file
		time.Sleep(30 * time.Second)
		return upload(f)
	}
	return err
}

Prevention

When it happens

Trigger: Uploading a file with --av scan enabled (VIRUSTOTAL/clamav passthrough) when clamd is overloaded, scanning a very large file over a slow clamd socket, or clamd is hung/down so the TCP connection stalls until the 60s timer fires.

Common situations: clamd daemon under heavy load or in signature-reload, clamd running on a remote host with network latency, scanning multi-hundred-MB uploads, or a misconfigured clamd address causing silent connection stalls.

Understand the failure class

Related errors


AI-assisted analysis of dutchcoders/transfer.sh@c37bfd9579 (2026-09-05). Data as JSON: /api/errors/e949c0a0d1d1c268. Report an issue: GitHub.