clamav-rest-api
clamav-rest-api copied to clipboard
got error when file too large
The following error occurs when a file is larger than APP_MAX_FILE_SIZE
.
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
I did the following steps:
- Change
APP_MAX_FILE_SIZE
in docker-compose.yml to 100 -
docker compose up
-
curl -X POST http://localhost:8080/api/v1/scan -F FILES=@src/tests/1Mfile01.rnd | jq
- Response is returned, but an error occurs after a little while
logs from containers:
node:internal/errors:496
ErrorCaptureStackTrace(err);
^
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at new NodeError (node:internal/errors:405:5)
at ServerResponse.setHeader (node:_http_outgoing:648:11)
at ServerResponse.header (/clamav-rest-api/node_modules/express/lib/response.js:794:10)
at ServerResponse.send (/clamav-rest-api/node_modules/express/lib/response.js:174:12)
at ServerResponse.json (/clamav-rest-api/node_modules/express/lib/response.js:278:15)
at /clamav-rest-api/src/routes/scan.js:30:30
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'ERR_HTTP_HEADERS_SENT'
}
How can I work around the error?
Hi,
The APP_MAX_FILE_SIZE
parameter should be provided in bytes. 100B can be too small to let CRA work properly.
Try to change this value to something more realistic: 10MB should be a good starting point
10 * 1024 * 1024 = 10485760
APP_MAX_FILE_SIZE=10485760
The value in the example docker-compose.yaml
file is 25MB for single file to scan
@benzino77 Thanks for your comment.
I set APP_MAX_FILE_SIZE
to 10MB (10485760) and tried a file larger than 10MB but got the same error.
api response:
{
"success": false,
"data": {
"error": "File size limit exceeded. Max size of uploaded file is: 10485760 KB"
}
}
If you set a limit to 10MB and send file greater then 10MB... well it is correct behavior.
APP_MAX_FILE_SIZE
is the upper size limit of a file which can be accepted by CRA.
@benzino77 Container restarts when an error occurs. Is it also correct behavior for the container to exit?
Sorry to hear it.
What is your setup? Are you trying to start CRA on docker or on k8s? Have you tried to use sample configuration from examples
directory?
I've just tested CRA on docker and k8s on my side using samples provided in examples
directory. Works without any problem - no restarts on uploading files exceeding size limit
For docker I'm on version:
docker --version
Docker version 25.0.3, build 4debf41
in case of k8s I've performed tests on 1.24.3
and 1.28.3
also works without restarts when file size limit is exceeded:
minikube profile list
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
| Profile | VM Driver | Runtime | IP | Port | Version | Status | Nodes | Active |
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
| cluster1 | docker | docker | 192.168.58.2 | 8443 | v1.28.3 | Running | 1 | |
| minikube | docker | docker | 192.168.49.2 | 8443 | v1.24.3 | Stopped | 1 | * |
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
I tried CRA on Docker using samples provided in examples
directory.
I use the same docker version.
docker --version
Docker version 25.0.3, build 4debf41
Hmm. That is strange. I just tested CRA on two different environments and it works as expected. Can you provide more details about your setup?
What architecture you are running on? x86_64? ARM64 (Apple M1/M2/Mx)?
What OS you are running underneath? Windows? Linux? MacOS?
Do you introduce any changes to sample docker-compose.yaml
file included in examples
directory?
I am using MacOS. I tried it in the following environments.
- x86_64
- ARM64(Apple M2)
All environments use Docker image benzino77/clamav-rest-api:1.2.2.
After a minute or two after the request, an error log is output and the system restarts. In some cases, it restarts immediately.
APP_MAX_FILE_SIZE
in docker-compose.yaml
is changed to 10485760. No other changes other than this.
I have been trying to reproduce your problem but without luck.
I have setup CRA on two different machines with docker. Set the max upload file to 1MB and upload random files in a loop to CRA to scan them. Most of the files exceeded APP_MAX_FILE_SIZE
. I haven't observed restarts.
Is it a "plain" docker installation or you introduce some "tweaks" in docker.json
file?
I think that finally I was able to reproduce your problem. Check the new docker image pushed to docker hub.
Close this issue as there is no response from the reporter.