Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

A cache storage that is not available is logged and skipped; Souin then serves from its unbounded in-memory storage

Ouverte
#145 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
48/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
go
Domaine
backend, devops

Piste de recherche

Start in dispatch.go at parseStorages and trace how configured storage UUIDs are registered and looked up during Provision, including the call immediately after s.parseStorages(ctx). Reproduce the large size lookup mismatch and failed SimpleFS provisioning described in the issue. Done means provisioning fails when a configured storage is unavailable, so Caddy does not silently serve from the in-memory default.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Versions: Caddy v2.11.4, cache-handler v0.17.0, github.com/darkweak/storages/simplefs/caddy v0.0.20 (built with xcaddy, nothing else).

When the storage a cache block configures is not available, cache-handler logs it and Souin serves every response from its in-memory default storage. Caddy accepts the configuration, caddy reload included, so its automatic rollback never applies, and every cached response then lives in Caddy's heap with no cap, although the configuration asked for a disk-backed, size-capped storage.

Two ways to get there, both reproduced on the versions above with this Caddyfile (only the configuration block changes):

{
	admin off
	cache {
		ttl 60s
		simplefs {
			configuration {
				path /tmp/simplefs
				size 1000000
			}
		}
	}
}
:8080 {
	cache
	header Cache-Control "public, max-age=60"
	respond "hello" 200
}

1. size of 1,000,000 or more. The storer provisions and creates its directory, but the lookup does not find it: the name cache-handler composes for the lookup formats the decoded size (a float64) as 1e+06, while the storer registers under 1000000. The only log line is Souin's warning:

{"level":"warn","logger":"http.handlers.cache","msg":"You're running Souin with the default storage that is not optimized and for development purpose. ..."}

and every hit reports Cache-Status: Souin; hit; ttl=59; key=GET-http-127.0.0.1:8080-/; detail=DEFAULT, with nothing written under /tmp/simplefs. With size 1000 the same Caddyfile serves detail=SIMPLEFS and writes the body files.

2. A storage that fails to provision, e.g. path /nope/simplefs (a directory the process cannot create). parseStorages (dispatch.go) logs the error and carries on:

{"level":"error","logger":"http.handlers.cache","msg":"Error during SimpleFS init, did you include the SimpleFS storage (--with github.com/darkweak/storages/simplefs/caddy)? provision storages.cache.simplefs: mkdir /nope: read-only file system"}

then the same warning, and the same detail=DEFAULT hits.

Suggested fix: fail Provision when a configured storage (Found) is not registered under the UUID Souin looks it up by. That covers both cases: a reload is then refused and Caddy keeps the config it ran, and a start fails. We run this as a small patch, called right after s.parseStorages(ctx) and before middleware.NewHTTPCacheHandler:

func (s *SouinCaddyMiddleware) requireConfiguredStorages() error {
	dc := s.Configuration.DefaultCache
	for _, configured := range []struct {
		name     string
		provider configurationtypes.CacheProvider
	}{
		{"badger", dc.Badger}, {"etcd", dc.Etcd}, {"nats", dc.Nats}, {"nuts", dc.Nuts},
		{"olric", dc.Olric}, {"otter", dc.Otter}, {"redis", dc.Redis}, {"simplefs", dc.SimpleFS},
	} {
		if configured.provider.Found &&
			(configured.provider.Uuid == "" || core.GetRegisteredStorer(configured.provider.Uuid) == nil) {
			return fmt.Errorf("the %s storage is configured but is not available (its error is logged above): refusing to serve from the in-memory storage", configured.name)
		}
	}
	return nil
}

Case 1 could also be fixed at the source, by formatting size as an integer in the lookup name, or by asking the provisioned storer for the name it registered under. Happy to open a PR for either.

Langage dominant
Go
Étoiles
395
Forks
30
Merge moyen
32 min
PR mergées (30 j)
1

Préparer son environnement

Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de caddyserver/cache-handler

Toutes les issues de caddyserver/cache-handler

Issues similaires

Plus d'issues Go

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.