Repository: nektos/act (language: go)

Issue:
upload-artifacts/download-artifacts@v4 not working with large files
### Bug report info

```plain text
act version:            0.2.63
GOOS:                   linux
GOARCH:                 amd64
NumCPU:                 8
Docker host:            DOCKER_HOST environment variable is not set
Sockets found:
        /var/run/docker.sock
Config files:           
        /home/arendjan/.actrc:
                -P ubuntu-latest=catthehacker/ubuntu:act-latest
                -P ubuntu-22.04=catthehacker/ubuntu:act-22.04
                -P ubuntu-20.04=catthehacker/ubuntu:act-20.04
                -P ubuntu-18.04=catthehacker/ubuntu:act-18.04
Build info:
        Go version:            go1.21.10
        Module path:           github.com/nektos/act
        Main version:          (devel)
        Main path:             github.com/nektos/act
        Main checksum:         
        Build settings:
                -buildmode:           exe
                -compiler:            gc
                -ldflags:             -s -w -X main.version=0.2.63 -X main.commit=c959fdd58835195916386b44a87632151a1b491a -X main.date=2024-06-01T02:17:39Z -X main.builtBy=goreleaser
                CGO_ENABLED:          0
                GOARCH:               amd64
                GOOS:                 linux
                GOAMD64:              v1
                vcs:                  git
                vcs.revision:         c959fdd58835195916386b44a87632151a1b491a
                vcs.time:             2024-06-01T02:17:21Z
                vcs.modified:         false
Docker Engine:
        Engine version:        26.1.4
        Engine runtime:        runc
        Cgroup version:        1
        Cgroup driver:         cgroupfs
        Storage driver:        overlay2
        Registry URI:          https://index.docker.io/v1/
        OS:                    Ubuntu 20.04.6 LTS
        OS type:               linux
        OS version:            20.04
        OS arch:               x86_64
        OS kernel:             5.15.153.1-microsoft-standard-WSL2
        OS CPU:                8
        OS memory:             7810 MB
        Security options:
                name=seccomp,profile=builtin
```


### Command used with act

```sh
act -v -j download_huge_file --artifact-server-path test/
```


### Describe issue

When uploading/downloading 'large' files, the v4 artifact system does not work and results in `::debug::Failed to download artifact after 1 retries due to Not a valid zip file. Retrying in 5 seconds...` and `::debug::response.message: Artifact download failed: Blob storage chunk did not respond in 30000ms` messages.

It worked with the v3 actions.

### Link to GitHub repository

_No response_

### Workflow content

```yml
name: test

on:
    [push]

jobs:
    upload_huge_file:
        runs-on: ubuntu-latest
        steps:
            - uses: actions/checkout@v4
            # create huge file, works with /dev/null, as the zip is compressed
            - run: dd if=/dev/random of=huge_file bs=1M count=1024
            - name: Upload huge file
              uses: actions/upload-artifact@v4
              with:
                  name: huge_file
                  path: huge_file
    download_huge_file:
        runs-on: ubuntu-latest
        needs: upload_huge_file
        steps:
            - uses: actions/checkout@v4
            - name: Download huge file
              uses: actions/download-artifact@v4
              with:
                  name: huge_file
            - run: ls -al
```


### Relevant log output

```sh
too long, uploaded to here: https://pastebin.com/Pv6eS2Eq
```


### Additional information

_No response_


Discussion / hints:
Probably the same issue as #2351 

Fix patch:
diff --git a/pkg/artifacts/arifacts_v4.go b/pkg/artifacts/arifacts_v4.go
index 9a1c8897e42..1d5611b7c02 100644
--- a/pkg/artifacts/arifacts_v4.go
+++ b/pkg/artifacts/arifacts_v4.go
@@ -271,6 +271,16 @@ func (r *artifactV4Routes) createArtifact(ctx *ArtifactContext) {
 
 	artifactName := req.Name
 
+	safeRunPath := safeResolve(r.baseDir, fmt.Sprint(runID))
+	safePath := safeResolve(safeRunPath, artifactName)
+	safePath = safeResolve(safePath, artifactName+".zip")
+	file, err := r.fs.OpenWritable(safePath)
+
+	if err != nil {
+		panic(err)
+	}
+	file.Close()
+
 	respData := CreateArtifactResponse{
 		Ok:              true,
 		SignedUploadUrl: r.buildArtifactURL("UploadArtifact", artifactName, runID),
@@ -292,12 +302,7 @@ func (r *artifactV4Routes) uploadArtifact(ctx *ArtifactContext) {
 		safePath := safeResolve(safeRunPath, artifactName)
 		safePath = safeResolve(safePath, artifactName+".zip")
 
-		file, err := func() (WritableFile, error) {
-			if comp == "appendBlock" {
-				return r.fs.OpenAppendable(safePath)
-			}
-			return r.fs.OpenWritable(safePath)
-		}()
+		file, err := r.fs.OpenAppendable(safePath)
 
 		if err != nil {
 			panic(err)
@@ -317,6 +322,7 @@ func (r *artifactV4Routes) uploadArtifact(ctx *ArtifactContext) {
 		if err != nil {
 			panic(err)
 		}
+		file.Close()
 		ctx.JSON(http.StatusCreated, "appended")
 	case "blocklist":
 		ctx.JSON(http.StatusCreated, "created")


Test patch: