3 Commits

Author SHA1 Message Date
27634d016b reset tcp connection if error happens
All checks were successful
build container / build-container (push) Successful in 4m33s
run go test / test (push) Successful in 3m56s
2025-02-22 23:27:41 +08:00
ab852a6520 make it work across instances
All checks were successful
run go test / test (push) Successful in 12m39s
build container / build-container (push) Successful in 8m3s
2025-02-19 21:30:49 +08:00
18bdc4f54e configure caches
Some checks are pending
build container / build-container (push) Waiting to run
run go test / test (push) Waiting to run
2025-02-19 20:50:21 +08:00
3 changed files with 44 additions and 3 deletions

View File

@ -8,13 +8,19 @@ env:
jobs:
build-container:
runs-on: bookworm
runs-on: docker
steps:
- name: Setup apt mirror
run: sed -i "s,deb.debian.org,${{ vars.DEBIAN_MIRROR }},g" ${{ vars.DEBIAN_APT_SOURCES }}
if: ${{ vars.DEBIAN_MIRROR && vars.DEBIAN_APT_SOURCES }}
- name: Setup debian environment
run: apt update && apt install -y podman podman-compose nodejs
- name: Setup cache for podman
uses: actions/cache@v4
with:
path: |
/var/lib/containers
key: podman-storage
- name: Check out repository code
uses: actions/checkout@v4
- name: Build container

View File

@ -7,22 +7,33 @@ on:
- go.mod
- go.lock
- go.work
- .gitea/workflows/go-test.yaml
env:
GOPROXY: ${{ vars.GOPROXY }}
jobs:
test:
runs-on: bookworm
runs-on: docker
steps:
- name: Setup apt mirror
run: sed -i "s,deb.debian.org,${{ vars.DEBIAN_MIRROR }},g" ${{ vars.DEBIAN_APT_SOURCES }}
if: ${{ vars.DEBIAN_MIRROR && vars.DEBIAN_APT_SOURCES }}
- name: Setup Debian environment
run: apt update && apt install -y nodejs
- name: Setup cache for golang toolchain
uses: actions/cache@v4
with:
path: |
/opt/hostedtoolcache/go
/root/go/pkg/mod
/root/.cache/go-build
key: ${{ runner.os }}-golang
- name: Setup Golang
uses: actions/setup-go@v5
with:
go-version: 1.24.0
cache-dependency-path: |
go.sum
- name: Check out repository code
uses: actions/checkout@v4
- name: Run tests

View File

@ -7,6 +7,7 @@ import (
"fmt"
"io"
"log/slog"
"net"
"net/http"
"os"
"path/filepath"
@ -332,7 +333,30 @@ func (server *Server) streamOnline(w http.ResponseWriter, r *http.Request, mtime
}
if err != nil {
slog.With("error", err, "upstreamIdx", selectedIdx).Error("something happened during download. will not cache this response")
logger := slog.With("upstreamIdx", selectedIdx)
logger.Error("something happened during download. will not cache this response. setting lingering to reset the connection.")
hijacker, ok := w.(http.Hijacker)
if !ok {
logger.Warn("response writer is not a hijacker. failed to set lingering")
return
}
conn, _, err := hijacker.Hijack()
if err != nil {
logger.With("error", err).Warn("hijack failed. failed to set lingering")
return
}
defer conn.Close()
tcpConn, ok := conn.(*net.TCPConn)
if !ok {
logger.With("error", err).Warn("connection is not a *net.TCPConn. failed to set lingering")
return
}
if err := tcpConn.SetLinger(0); err != nil {
logger.With("error", err).Warn("failed to set lingering")
return
}
logger.Debug("connection set to linger. it will be reset once the conn.Close is called")
}
go func() {
defer func() {