You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: versioned_docs/version-v3.x/api/ctx.md
+15-7Lines changed: 15 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1150,7 +1150,11 @@ By default, `c.IP()` returns the remote IP address from the TCP connection. When
1150
1150
1151
1151
**Important:** You must enable `TrustProxy` and configure trusted proxy IPs to prevent header spoofing. Simply setting `ProxyHeader` alone will not work.
1152
1152
1153
-
**Note:** When using a proxy header such as `X-Forwarded-For`, `c.IP()` returns the raw header value unless [`EnableIPValidation`](fiber.md#enableipvalidation) is enabled. For `X-Forwarded-For`, this raw value may be a comma-separated list of IPs; enable `EnableIPValidation` if you need `c.IP()` to return a single, validated client IP.
1153
+
**Note:** When using a proxy header such as `X-Forwarded-For`, `c.IP()` returns the raw header value unless [`EnableIPValidation`](fiber.md#enableipvalidation) is enabled.
1154
+
1155
+
**Chain parsing with `EnableIPValidation`:** For `X-Forwarded-For`, the raw value is a comma-separated chain that grows from left to right as the request passes through each proxy. With validation enabled, `c.IP()` walks the chain from right to left, skipping every IP that matches the configured `TrustProxyConfig` (exact IPs, CIDR ranges, loopback, private or link-local) and returns the first non-trusted IP it finds. This matches the behavior recommended by [MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Forwarded-For#selecting_an_ip_address) and the convention used by Nginx (`set_real_ip_from` + `real_ip_recursive`), Apache `mod_remoteip`, and Envoy (`xff_num_trusted_hops`).
1156
+
1157
+
If every IP in the chain matches the trusted set, the leftmost IP is returned as a fallback. If the chain is empty, `c.IP()` falls back to the TCP remote address.
1154
1158
:::
1155
1159
1156
1160
#### Configuration for apps behind a reverse proxy
| <Referenceid="ShutdownTimeout">ShutdownTimeout</Reference> |`time.Duration`| Specifies the maximum duration to wait for the server to gracefully shutdown. When the timeout is reached, the graceful shutdown process is interrupted and forcibly terminated, and the `context.DeadlineExceeded` error is passed to the `OnPostShutdown` callback. Set to 0 to disable the timeout and wait indefinitely. |`10 * time.Second`|
121
121
| <Referenceid="listeneraddrfunc">ListenerAddrFunc</Reference> |`func(addr net.Addr)`| Allows accessing and customizing `net.Listener`. |`nil`|
122
122
| <Referenceid="listenernetwork">ListenerNetwork</Reference> |`string`| Known networks are "tcp", "tcp4" (IPv4-only), "tcp6" (IPv6-only), "unix" (Unix Domain Sockets). WARNING: When prefork is set to true, only "tcp4" and "tcp6" can be chosen. |`tcp4`|
123
+
| <Referenceid="preforkrecoverinterval">PreforkRecoverInterval</Reference> |`time.Duration`| Delays the respawn of a crashed child process by this duration. Only applies when prefork is enabled. |`0` (respawn immediately) |
123
124
| <Referenceid="preforkrecoverthreshold">PreforkRecoverThreshold</Reference> |`int`| Defines the maximum number of child process restarts after crashes before the prefork master exits with an error. Only applies when prefork is enabled. |`max(1, runtime.GOMAXPROCS(0) / 2)`|
125
+
| <Referenceid="preforkshutdowngraceperiod">PreforkShutdownGracePeriod</Reference> |`time.Duration`| How long the prefork master waits for child processes to exit after SIGTERM before sending SIGKILL during shutdown. On Windows children are always killed immediately. Only applies when prefork is enabled. |`5 * time.Second`|
124
126
| <Referenceid="preforklogger">PreforkLogger</Reference> |`PreforkLogger`| Sets a custom logger for the prefork process manager. Only applies when prefork is enabled. | Fiber logger |
125
127
| <Referenceid="unixsocketfilemode">UnixSocketFileMode</Reference> |`os.FileMode`| FileMode to set for Unix Domain Socket (ListenerNetwork must be "unix") |`0770`|
126
128
| <Referenceid="tlsconfigfunc">TLSConfigFunc</Reference> |`func(tlsConfig *tls.Config)`| Allows customizing `tls.Config` as you want. Ignored when `TLSConfig` is set. |`nil`|
Copy file name to clipboardExpand all lines: versioned_docs/version-v3.x/extra/faq.md
+21Lines changed: 21 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -198,3 +198,24 @@ For details on how to:
198
198
* Convert `fiber.Ctx` to `http.Request`
199
199
200
200
See the dedicated documentation: [Adaptor Documentation](../middleware/adaptor.md).
201
+
202
+
## Troubleshooting common errors
203
+
204
+
Crashes that surface in unrelated packages, with stack traces that never mention Fiber, usually trace back to a context value kept past the handler. The cases below name the symptom so a search for the panic text lands here.
This is not a bug in Fiber, gRPC, or `golang.org/x/net/http2`. It means a Fiber zero-copy context value (a header from `c.Get`, or `c.Query`, `c.Params`, `c.Cookies`, `c.Body`) was kept past the handler. Fiber reuses the request buffer on the next request, so the retained bytes change underneath whatever stored them. See [Zero Allocation](../intro.md#zero-allocation) for the underlying behavior.
209
+
210
+
A common trigger is forwarding a header into a long-lived gRPC / HTTP/2 client's `metadata`. The value is held in the connection's HPACK dynamic table and later mutates, crashing the process inside the HPACK encoder, in a stack trace that never mentions Fiber:
The crash is decoupled from your handler in both time and call stack, so ordinary tests and even the `-race` detector usually miss it.
220
+
221
+
The fix is to detach the value before you keep it: copy it with `utils.CopyString` (or `strings.Clone`), or enable [`Immutable`](../api/fiber.md#immutable). A full reproduction is in [gofiber/fiber#4464](https://github.com/gofiber/fiber/issues/4464).
0 commit comments