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

ECONNREFUSED 127.0.0.1:3310 #29

Open
slehernaf opened this issue May 23, 2022 · 16 comments
Open

ECONNREFUSED 127.0.0.1:3310 #29

slehernaf opened this issue May 23, 2022 · 16 comments

Comments

@slehernaf
Copy link

slehernaf commented May 23, 2022

I do not know why, but during startup, the container is displayed as active and disappears after 2-3 seconds, this error is found in the logs
Cannot initialize clamav object: Error: connect ECONNREFUSED 127.0.0.1:3310
netstat -lnp | grep -E "(clam|3310|docker)" ->

netstat result

@benzino77
Copy link
Owner

Hi!
Do you have CRA and ClamAV started in docker?

@slehernaf
Copy link
Author

No, i tried started with ClamAV in docker, but the error still remained

@benzino77
Copy link
Owner

But CRA is started inside container? If so, you cannot use localhost/127.0.0.1 as Clamavd address because localhost/127.0.0.1 inside container is not the same as your host ;)

@slehernaf
Copy link
Author

I'm sorry, I just started dealing with dockers and I don't understand a lot yet, so I can only give screenshots.
Here is a port scan:
netstat result
Here it shows how the image is launched, that the container is created and disappears, and logs
netstat result
You can also see here that the container is running on 3310/tcp, this is the clamav/clamav image

@benzino77
Copy link
Owner

OK. So here is the problem: you have not specified CLAMD_IP env variable for CRA container so it defaults to localhost/127.0.0.1 (you just copy paste command from README without pointing to proper config file).
You have to set this environment variable to your host (computer you are running docker-engine) IP. You can do this by running CRA container with the command:

docker run -d -p 8080:8080 -e NODE_ENV=production -e APP_PORT=8080 -e APP_FORM_KEY=FILES -e CLAMD_IP=<put_here_ip_address_of_your_machine> benzino77/clamav-rest-api

@sankar2389
Copy link

sankar2389 commented May 26, 2022

clamav/clamav:latest - I'm running the clamav docker container & ip address added in .env CLAMD_IP - 172.17.0.2

got this ip address by below command
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' de7a835c5681

But still getting error as ECONNREFUSED

Ist there any steps to follow?

@benzino77
Copy link
Owner

You should not use it that way - that address will change every time you restart clamavd container.
Have a look in the examples folder
If you do not want to use docker-compose you should try to set up things like that:

  1. Get your host (the VM/machine on which docker -engine is running) IP address
  2. start clamvad as container and expose port 3310
  3. start CRA container and point CLAMD_IP to the IP from step 1

@a-sarja
Copy link

a-sarja commented Oct 28, 2022

@benzino77 I m facing the same error. I am trying to start clamav-rest-api app by cloning the repo and running the clamav docker container locally. But for some reason, I am facing ECONNREFUSED error.

P.S - I have tried with setting the ENV variables in different ways (.env file and also as shown in the screenshot) with VM IP address, 127.0.0.1 and localhost for CLAMD_IP - but the result is the same

image

@benzino77
Copy link
Owner

benzino77 commented Oct 28, 2022

CRA will not start if there is no clamav daemon available (or I should rather say there is no clamavd with open 3310 port available). As I can see from the screenshot you provided you have not publish clamav port to the host. You should start clamav container by something similar to:

docker run -d --name clamavd -p 3310:3310 clamav/clamav:stable

The important part is -p 3310:3310

@a-sarja
Copy link

a-sarja commented Oct 28, 2022

Thank you, that worked! I think it is better to update the README about the same, since I do not see this info there. Cheers!

@benzino77
Copy link
Owner

Thank you, that worked! I think it is better to update the README about the same, since I do not see this info there. Cheers!

PRs are welcome ;)

@Dunae
Copy link

Dunae commented Jan 31, 2024

Hi i m running in kubernetes clamav and cra, i changed cra service type from nodeport to loadbalancer because i need an public ip for the endoint, is working for a day and after a day i receive
{
"success": false,
"data": {
"error": "connect ECONNREFUSED 10.0.0.86:3310"
}
}

@benzino77
Copy link
Owner

Hi,
That is because there is no clamav service available.
Where do you try to start CRA: Docker? K8S?

could you please provide your setup: docker-compose.yaml or your k8s manifests?

@Dunae
Copy link

Dunae commented Feb 2, 2024

Hi, thank you for quick respose, please see the manifests below:
apiVersion: apps/v1
kind: Deployment
metadata:
name: clamavd-deployment
labels:
app: clamavd
spec:
replicas: 1
selector:
matchLabels:
app: clamavd
template:
metadata:
labels:
app: clamavd
spec:
containers:
- name: clamavd
image: clamav/clamav:stable
ports:
- containerPort: 3310
protocol: TCP
name: clamavd-port
volumeMounts:
- name: clamav-config-volume
mountPath: /etc/clamav
resources:
limits:
memory: "2Gi"
requests:
memory: "1Gi"
volumes:
- name: clamav-config-volume
configMap:
name: clamav-config

apiVersion: v1
kind: Service
metadata:
name: clamavd-service
spec:
selector:
app: clamavd
ports:
- protocol: TCP
port: 3310
targetPort: 3310

apiVersion: apps/v1
kind: Deployment
metadata:

Unique key of the Deployment instance

name: cra-deployment
labels:
app: cra
spec:
replicas: 1
selector:
matchLabels:
app: cra
template:
metadata:
labels:
# Apply this label to pods and default
# the Deployment label selector to this value
app: cra
spec:
containers:
- name: clamav-rest-api
# Run this image
image: benzino77/clamav-rest-api
command: ['/usr/bin/wait-for-it', '-h', 'clamavd-service', '-p', '3310', '-s', '-t', '60', '--', 'npm', 'start']
env:
- name: NODE_ENV
valueFrom:
configMapKeyRef:
name: cra-configmap
key: node-env
- name: CLAMD_IP
valueFrom:
configMapKeyRef:
name: cra-configmap
key: clamd-ip
- name: APP_FORM_KEY
valueFrom:
configMapKeyRef:
name: cra-configmap
key: app-form-key
- name: APP_MAX_FILE_SIZE
valueFrom:
configMapKeyRef:
name: cra-configmap
key: app-max-file-size
ports:
- containerPort: 3000
protocol: TCP
name: cra-port

apiVersion: v1
kind: Service
metadata:
name: cra-service
annotations:

service.beta.kubernetes.io/azure-load-balancer-internal: "true"

spec:
type: LoadBalancer
selector:
app: cra
ports:
- protocol: TCP
port: 3000
targetPort: cra-port

is working for a day lets say and next day the error

@rushi-hy
Copy link

rushi-hy commented Jul 18, 2024

I am getting this log in clamav-api docker service
Cannot initialize clamav object: Error: Did not get a PONG response from clamscan server.
Server started on PORT: 8080

Is this okay or should I do something?
Please help

Here is my compose file
`
version: '3.8'

services:
clamav:
image: clamav/clamav:stable
ports:
- "3310:3310"
restart: always

clamav-api:
image: benzino77/clamav-rest-api
ports:
- "8080:8080"
environment:
- NODE_ENV=production
- APP_PORT=8080
- APP_FORM_KEY=FILES
- CLAMD_IP=<my_vm_ip>
- APP_MAX_FILE_SIZE=50000000 # 50 MB
restart: always
depends_on:
- clamav
`

@benzino77
Copy link
Owner

clamav-api service depends on clamav service, which needs to be started to let clamav-api service to talk to it.
It (clamav service) will eventually start (it needs some time to download latest virus DB etc.) and clamav-api service (during next restart, which is handled by docker itself) will be able to connect to that service.

❯ docker compose up
WARN[0000] /home/benzino/Dokumenty/clamav-rest-api/examples/docker-compose.yml: `version` is obsolete
[+] Running 7/7
 ✔ clamd Pulled                                                                                                                                                                         45.4s
   ✔ 213ec9aee27d Pull complete                                                                                                                                                          1.8s
   ✔ 4d182891c628 Pull complete                                                                                                                                                          2.6s
   ✔ 12f08a2c066e Pull complete                                                                                                                                                          2.7s
   ✔ 036989e6794d Pull complete                                                                                                                                                          2.7s
   ✔ db98dc6dd1b9 Pull complete                                                                                                                                                          2.9s
   ✔ ffb9fc35f7e7 Pull complete                                                                                                                                                         42.1s
[+] Running 3/3
 ✔ Network examples_clam-net   Created                                                                                                                                                   0.1s
 ✔ Container examples-clamd-1  Created                                                                                                                                                   0.1s
 ✔ Container examples-api-1    Created                                                                                                                                                   0.0s
Attaching to api-1, clamd-1
clamd-1  | Starting ClamAV
clamd-1  | LibClamAV Warning: **************************************************
clamd-1  | LibClamAV Warning: ***  The virus database is older than 7 days!  ***
clamd-1  | LibClamAV Warning: ***   Please update it as soon as possible.    ***
clamd-1  | LibClamAV Warning: **************************************************
api-1    |
api-1    | > [email protected] start
api-1    | > node src/app.js
api-1    |
api-1    | Cannot initialize clamav object: Error: connect ECONNREFUSED 172.19.0.2:3310
api-1 exited with code 0
api-1    |
api-1    | > [email protected] start
api-1    | > node src/app.js
api-1    |
api-1    | Cannot initialize clamav object: Error: connect ECONNREFUSED 172.19.0.2:3310
api-1 exited with code 0
api-1    |
api-1    | > [email protected] start
api-1    | > node src/app.js
api-1    |
api-1    | Cannot initialize clamav object: Error: connect ECONNREFUSED 172.19.0.2:3310
api-1    |
api-1    | > [email protected] start
api-1    | > node src/app.js
api-1    |
api-1    | Cannot initialize clamav object: Error: connect ECONNREFUSED 172.19.0.2:3310
api-1    |
api-1    | > [email protected] start
api-1    | > node src/app.js
api-1    |
api-1    | Cannot initialize clamav object: Error: connect ECONNREFUSED 172.19.0.2:3310
api-1    |
api-1    | > [email protected] start
api-1    | > node src/app.js
api-1    |
api-1    | Cannot initialize clamav object: Error: connect ECONNREFUSED 172.19.0.2:3310
api-1    |
api-1    | > [email protected] start
api-1    | > node src/app.js
api-1    |
api-1    | Cannot initialize clamav object: Error: connect ECONNREFUSED 172.19.0.2:3310
api-1    |
api-1    | > [email protected] start
api-1    | > node src/app.js
api-1    |
api-1    | Cannot initialize clamav object: Error: connect ECONNREFUSED 172.19.0.2:3310
Socket for clamd not found yet, retrying (19/1800) ...Fri Jul 19 08:54:20 2024 -> Limits: Global time limit set to 120000 milliseconds.
clamd-1  | Fri Jul 19 08:54:20 2024 -> Limits: Global size limit set to 104857600 bytes.
clamd-1  | Fri Jul 19 08:54:20 2024 -> Limits: File size limit set to 26214400 bytes.
clamd-1  | Fri Jul 19 08:54:20 2024 -> Limits: Recursion level limit set to 17.
clamd-1  | Fri Jul 19 08:54:20 2024 -> Limits: Files limit set to 10000.
clamd-1  | Fri Jul 19 08:54:20 2024 -> Limits: MaxEmbeddedPE limit set to 10485760 bytes.
clamd-1  | Fri Jul 19 08:54:20 2024 -> Limits: MaxHTMLNormalize limit set to 10485760 bytes.
clamd-1  | Fri Jul 19 08:54:20 2024 -> Limits: MaxHTMLNoTags limit set to 2097152 bytes.
clamd-1  | Fri Jul 19 08:54:20 2024 -> Limits: MaxScriptNormalize limit set to 5242880 bytes.
clamd-1  | Fri Jul 19 08:54:20 2024 -> Limits: MaxZipTypeRcg limit set to 1048576 bytes.
clamd-1  | Fri Jul 19 08:54:20 2024 -> Limits: MaxPartitions limit set to 50.
clamd-1  | Fri Jul 19 08:54:20 2024 -> Limits: MaxIconsPE limit set to 100.
clamd-1  | Fri Jul 19 08:54:20 2024 -> Limits: MaxRecHWP3 limit set to 16.
clamd-1  | Fri Jul 19 08:54:20 2024 -> Limits: PCREMatchLimit limit set to 100000.
clamd-1  | Fri Jul 19 08:54:20 2024 -> Limits: PCRERecMatchLimit limit set to 2000.
clamd-1  | Fri Jul 19 08:54:20 2024 -> Limits: PCREMaxFileSize limit set to 26214400.
clamd-1  | Fri Jul 19 08:54:20 2024 -> Archive support enabled.
clamd-1  | Fri Jul 19 08:54:20 2024 -> AlertExceedsMax heuristic detection disabled.
clamd-1  | Fri Jul 19 08:54:20 2024 -> Heuristic alerts enabled.
clamd-1  | Fri Jul 19 08:54:20 2024 -> Portable Executable support enabled.
clamd-1  | Fri Jul 19 08:54:20 2024 -> ELF support enabled.
clamd-1  | Fri Jul 19 08:54:20 2024 -> Mail files support enabled.
clamd-1  | Fri Jul 19 08:54:20 2024 -> OLE2 support enabled.
clamd-1  | Fri Jul 19 08:54:20 2024 -> PDF support enabled.
clamd-1  | Fri Jul 19 08:54:20 2024 -> SWF support enabled.
clamd-1  | Fri Jul 19 08:54:20 2024 -> HTML support enabled.
clamd-1  | Fri Jul 19 08:54:20 2024 -> XMLDOCS support enabled.
clamd-1  | Fri Jul 19 08:54:20 2024 -> HWP3 support enabled.
clamd-1  | Fri Jul 19 08:54:20 2024 -> Self checking every 600 seconds.
clamd-1  | Fri Jul 19 08:54:20 2024 -> Set stacksize to 1048576
clamd-1  | socket found, clamd started.
clamd-1  | Starting Freshclamd
clamd-1  | ClamAV update process started at Fri Jul 19 08:54:20 2024
clamd-1  | daily database available for update (local version: 26644, remote version: 27340) <-------- CLAMAV SERVICE AVAILABLE
clamd-1  | WARNING: downloadFile: file not found: https://database.clamav.net/daily-26645.cdiff
clamd-1  | WARNING: downloadPatch: Can't download daily-26645.cdiff from https://database.clamav.net/daily-26645.cdiff
clamd-1  | WARNING: downloadFile: file not found: https://database.clamav.net/daily-26645.cdiff
clamd-1  | WARNING: downloadPatch: Can't download daily-26645.cdiff from https://database.clamav.net/daily-26645.cdiff
clamd-1  | WARNING: downloadFile: file not found: https://database.clamav.net/daily-26645.cdiff
clamd-1  | WARNING: downloadPatch: Can't download daily-26645.cdiff from https://database.clamav.net/daily-26645.cdiff
clamd-1  | WARNING: Incremental update failed, trying to download daily.cvd
api-1    |
api-1    | > [email protected] start
api-1    | > node src/app.js
api-1    |
api-1    | Server started on PORT: 3000 <------------ CLAMAV-API SERVICE STARTED
clamd-1  | Testing database: '/var/lib/clamav/tmp.debcc5f809/clamav-c1f95ff8fedc4f5f1c4d60abd22248ea.tmp-daily.cvd' ...
clamd-1  | Database test passed.
clamd-1  | daily.cvd updated (version: 27341, sigs: 2064527, f-level: 90, builder: raynman)
clamd-1  | main.cvd database is up-to-date (version: 62, sigs: 6647427, f-level: 90, builder: sigmgr)
clamd-1  | bytecode database available for update (local version: 333, remote version: 335)
clamd-1  | Empty script bytecode-334.cdiff, need to download entire database
clamd-1  | Testing database: '/var/lib/clamav/tmp.debcc5f809/clamav-cd7d6df3681bf42394d7c74bc4f6cda6.tmp-bytecode.cvd' ...
clamd-1  | Database test passed.
clamd-1  | bytecode.cvd updated (version: 335, sigs: 86, f-level: 90, builder: raynman)
clamd-1  | Clamd successfully notified about the update.
clamd-1  | Fri Jul 19 08:54:43 2024 -> Reading databases from /var/lib/clamav

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

6 participants