Skip to content

fix sigsev on bind permissions denied (#2250?)#2251

Merged
henderkes merged 4 commits intomainfrom
fix/shutdown-sigsev
Mar 9, 2026
Merged

fix sigsev on bind permissions denied (#2250?)#2251
henderkes merged 4 commits intomainfrom
fix/shutdown-sigsev

Conversation

@henderkes
Copy link
Contributor

Previous behaviour was bugged from somewhere between 1.11.3 and 1.12.0:

❯❯ frankenphp git:(main) 10:46 ./frankenphp php-server
2026/03/08 03:46:36.541 WARN    admin   admin endpoint disabled
2026/03/08 03:46:36.541 WARN    http.auto_https server is listening only on the HTTP port, so no automatic HTTPS will be applied to this server {"server_name": "php", "http_port": 80}
2026/03/08 03:46:36.542 INFO    tls.cache.maintenance   started background certificate maintenance      {"cache": "0x182aaec16500"}
2026/03/08 03:46:36.582 INFO    frankenphp      FrankenPHP started 🐘   {"php_version": "8.6.0-dev", "num_threads": 32, "max_threads": 32}
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0xb436bf]

goroutine 1 [running]:
github.com/caddyserver/caddy/v2.(*Context).Value(0x182aaedbe078?, {0x1e2d340?, 0x25e0c90?})
        <autogenerated>:1 +0x1f
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*extraFieldsSlogHandler).Handle(_, {_, _}, {{0xc2635a2724e776c5, 0x67b02fd, 0x3ca5000}, {0x22f7b13, 0x17}, 0x0, 0x1b7943e, ...})
        /home/m/go/pkg/mod/github.com/caddyserver/caddy/v2@v2.11.2/modules/caddyhttp/logging.go:308 +0x4c
log/slog.(*Logger).logAttrs(0x182aaea2bc30, {0x260a170?, 0x182aae96ad20?}, 0x0, {0x22f7b13, 0x17}, {0x0, 0x0, 0x0})
        /home/m/static-php-cli/pkgroot/x86_64-linux/go-xcaddy/src/log/slog/logger.go:276 +0x277
log/slog.(*Logger).LogAttrs(...)
        /home/m/static-php-cli/pkgroot/x86_64-linux/go-xcaddy/src/log/slog/logger.go:194
github.com/dunglas/frankenphp/caddy.(*FrankenPHPApp).Stop(0x182aae844300)
        /home/m/frankenphp/caddy/app.go:182 +0x14b
github.com/caddyserver/caddy/v2.run.func2(...)
        /home/m/go/pkg/mod/github.com/caddyserver/caddy/v2@v2.11.2/caddy.go:460
github.com/caddyserver/caddy/v2.run(0x25d1e48?, 0x1)
        /home/m/go/pkg/mod/github.com/caddyserver/caddy/v2@v2.11.2/caddy.go:471 +0x977
github.com/caddyserver/caddy/v2.unsyncedDecodeAndRun({0x182aaee76400, 0x3ad, 0x400}, 0x1)
        /home/m/go/pkg/mod/github.com/caddyserver/caddy/v2@v2.11.2/caddy.go:364 +0x17a
github.com/caddyserver/caddy/v2.changeConfig({0x22c19cb, 0x4}, {0x22c7b94, 0x7}, {0x182aaee76000, 0x3ad, 0x400}, {0x0, 0x0}, 0x1)
        /home/m/go/pkg/mod/github.com/caddyserver/caddy/v2@v2.11.2/caddy.go:248 +0x959
github.com/caddyserver/caddy/v2.Load({0x182aaee76000, 0x3ad, 0x400}, 0x1)
        /home/m/go/pkg/mod/github.com/caddyserver/caddy/v2@v2.11.2/caddy.go:137 +0x225
github.com/caddyserver/caddy/v2.Run(0x1fdb7a0?)
        /home/m/go/pkg/mod/github.com/caddyserver/caddy/v2@v2.11.2/caddy.go:109 +0x3b
github.com/dunglas/frankenphp/caddy.cmdPHPServer({0x0?})
        /home/m/frankenphp/caddy/php-server.go:320 +0x27b6
github.com/dunglas/frankenphp/caddy.init.4.func1.WrapCommandFuncForCobra.1(0x182aaee53808, {0x22c1a77?, 0x4?, 0x22c1a03?})
        /home/m/go/pkg/mod/github.com/caddyserver/caddy/v2@v2.11.2/cmd/cobra.go:151 +0x2f
github.com/spf13/cobra.(*Command).execute(0x182aaee53808, {0x3cc96a0, 0x0, 0x0})
        /home/m/go/pkg/mod/github.com/spf13/cobra@v1.10.2/command.go:1015 +0xb14
github.com/spf13/cobra.(*Command).ExecuteC(0x182aae7fbb08)
        /home/m/go/pkg/mod/github.com/spf13/cobra@v1.10.2/command.go:1148 +0x465
github.com/spf13/cobra.(*Command).Execute(...)
        /home/m/go/pkg/mod/github.com/spf13/cobra@v1.10.2/command.go:1071
github.com/caddyserver/caddy/v2/cmd.Main()
        /home/m/go/pkg/mod/github.com/caddyserver/caddy/v2@v2.11.2/cmd/main.go:72 +0x65
main.main()
        /home/m/frankenphp/caddy/frankenphp/main.go:14 +0xf

This restores it to exit cleanly again:

        /home/m/frankenphp/caddy/frankenphp/main.go:14 +0xf
❯❯ frankenphp git:(main)  10:46 go build 
❯❯ frankenphp git:(main) 10:58 ./frankenphp php-server
2026/03/08 03:58:01.533 WARN    admin   admin endpoint disabled
2026/03/08 03:58:01.533 WARN    http.auto_https server is listening only on the HTTP port, so no automatic HTTPS will be applied to this server {"server_name": "php", "http_port": 80}
2026/03/08 03:58:01.533 INFO    tls.cache.maintenance   started background certificate maintenance      {"cache": "0x850ebf79280"}
2026/03/08 03:58:01.556 INFO    tls.cache.maintenance   stopped background certificate maintenance      {"cache": "0x850ebf79280"}
2026/03/08 03:58:01.556 INFO    http    servers shutting down with eternal grace period
Error: loading new config: http app module: start: listening on :80: listen tcp :80: bind: permission denied

Comment on lines +179 to +180
if f.logger.Enabled(f.ctx, slog.LevelInfo) {
f.logger.LogAttrs(f.ctx, slog.LevelInfo, "FrankenPHP stopped 🐘")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if we have to refetch the context here. If we do, I'll revert this of course, but in my testing this works.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me.

TBH, I would only keep this change in this PR, other changes are unrelated to the issue and maybe touchy.

@henderkes henderkes requested a review from dunglas March 8, 2026 06:57
@henderkes
Copy link
Contributor Author

idk how to request @Copilot or @claude

@alexandre-daubois
Copy link
Member

On a phone right now so I can't review correctly myself, but I requested Copilot review for you 👍

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a crash during shutdown when php-server fails to bind to a privileged port (e.g., :80 without sufficient permissions), restoring clean exit behavior and proper error reporting in FrankenPHP’s Caddy integration.

Changes:

  • Use the app’s provisioned context (f.ctx) for shutdown logging instead of caddy.ActiveContext() to avoid nil-context panics.
  • When Caddy is exiting, trigger a full FrankenPHP shutdown in addition to draining workers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@henderkes henderkes merged commit d1fcf06 into main Mar 9, 2026
31 checks passed
@henderkes henderkes deleted the fix/shutdown-sigsev branch March 9, 2026 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants