Csilk 0.2.1
A lightweight, high-performance C HTTP web framework
Loading...
Searching...
No Matches
recovery.c File Reference

Panic recovery middleware implementation. More...

#include <setjmp.h>
#include <stdio.h>
#include <stdlib.h>
#include "context_internal.h"
#include "csilk/core/internal.h"
#include "csilk/csilk.h"
Include dependency graph for recovery.c:

Functions

void csilk_recovery_handler (csilk_ctx_t *c)
 Panic recovery middleware — catches longjmp panics and returns 500.
 
void csilk_panic (csilk_ctx_t *c)
 Trigger a panic (longjmp to recovery handler) or abort if no recovery registered.
 

Detailed Description

Panic recovery middleware implementation.

Function Documentation

◆ csilk_panic()

void csilk_panic ( csilk_ctx_t *  c)

Trigger a panic (longjmp to recovery handler) or abort if no recovery registered.

Trigger a panic (caught by recovery middleware).

If a recovery handler has been installed (c->has_jump_buffer is set), this function performs a longjmp back to the recovery point set by csilk_recovery_handler().

If no recovery handler is registered, it prints a fatal error message to stderr and calls exit(1) to terminate the process.

Parameters
cThe request context. May be NULL (will trigger abort path).
Warning
This function does NOT return when executed without a recovery handler.

◆ csilk_recovery_handler()

void csilk_recovery_handler ( csilk_ctx_t *  c)

Panic recovery middleware — catches longjmp panics and returns 500.

Panic-recovery middleware.

Installs a setjmp recovery point before calling csilk_next(). If any downstream handler triggers csilk_panic(), execution resumes at the setjmp point and an "Internal Server Error" response (500) is sent instead of crashing the process.

After the normal (non-panic) path completes, the jump buffer flag is cleared.

Parameters
cThe request context (must have a valid jump_buffer).
Note
This middleware MUST be registered before any handler that may call csilk_panic().
Warning
setjmp/longjmp do NOT unwind the C stack or call destructors. Resources allocated by panicked handlers (malloc, open files, etc.) WILL leak. Use this as a last-resort safety net, not as a primary error-handling mechanism.