Skip to content

Commit

Permalink
cmd: Better error handling when reloading (caddyserver#6601)
Browse files Browse the repository at this point in the history
* caddyhttp: Limit auto-HTTPS error logs to 100 domains

* Improve error message and increase error size limit
  • Loading branch information
mholt authored Oct 2, 2024
1 parent 9b4acc2 commit c8adb1b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/commandfuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ func AdminAPIRequest(adminAddr, method, uri string, headers http.Header, body io

// if it didn't work, let the user know
if resp.StatusCode >= 400 {
respBody, err := io.ReadAll(io.LimitReader(resp.Body, 1024*10))
respBody, err := io.ReadAll(io.LimitReader(resp.Body, 1024*1024*2))
if err != nil {
return nil, fmt.Errorf("HTTP %d: reading error message: %v", resp.StatusCode, err)
}
Expand Down
2 changes: 1 addition & 1 deletion modules/caddyhttp/autohttps.go
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ func (app *App) automaticHTTPSPhase2() error {
)
err := app.tlsApp.Manage(app.allCertDomains)
if err != nil {
return fmt.Errorf("managing certificates for %v: %s", app.allCertDomains, err)
return fmt.Errorf("managing certificates for %d domains: %s", len(app.allCertDomains), err)
}
app.allCertDomains = nil // no longer needed; allow GC to deallocate
return nil
Expand Down
4 changes: 4 additions & 0 deletions modules/caddytls/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,10 @@ func (t *TLS) Manage(names []string) error {
for ap, names := range policyToNames {
err := ap.magic.ManageAsync(t.ctx.Context, names)
if err != nil {
const maxNamesToDisplay = 100
if len(names) > maxNamesToDisplay {
names = append(names[:maxNamesToDisplay], fmt.Sprintf("(%d more...)", len(names)-maxNamesToDisplay))
}
return fmt.Errorf("automate: manage %v: %v", names, err)
}
for _, name := range names {
Expand Down

0 comments on commit c8adb1b

Please sign in to comment.