Skip to content

Set reasonable default network timeouts instead of "infinite" - #2316

Open
mnapoli wants to merge 3 commits into
4.xfrom
socket-timeouts
Open

mnapoli wants to merge 3 commits into
4.xfrom
socket-timeouts

Conversation

@mnapoli

@mnapoli mnapoli commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

A network call that never answers (an HTTP API, Redis, a MySQL query) keeps waiting until Lambda stops the invocation: no exception, nothing for Sentry, the framework's error handling never runs. PHP's defaults don't help: default_socket_timeout is 60 seconds and mysqlnd.net_read_timeout is 1 day.

Bref now lowers both settings to the time left in the invocation minus 2 seconds, so the call fails with a timeout error the application can handle:

  • function runtime: ini_set() before the handler, restored after the invocation,
  • PHP-FPM: PHP_VALUE on every request (PHP-FPM keeps the values of a request for the next ones),
  • console runtime: -d options on the command.

They are never raised: a lower value configured in php.ini is kept. 2 seconds because Bref stops PHP-FPM 1 second before the timeout, which leaves 1 second to handle the error.

Signals (pcntl_alarm(), like #895) can't do this: I tested PHP 8.4 in FPM and in the CLI, and the handler only runs once a blocked connect/curl/PDO call returns.

Not covered: curl and Guzzle (including the Laravel HTTP client and the AWS SDK) and PostgreSQL queries, which ignore both settings. The v4 upgrade guide says so, and documents the 20 second database connect timeout added to the bridges in brefphp/laravel-bridge#232 and brefphp/symfony-bridge#87.

Behaviour change, hence v4 only.

The max_execution_time TODO in FpmHandler is removed: the layers now set max_execution_time=0 (brefphp/aws-lambda-layers#365), and Bref's own timeout already covers FPM requests, counting the time spent waiting.

Upgrade guide section

default_socket_timeout and mysqlnd.net_read_timeout are lowered to the
time left in the invocation minus 2 seconds, in the function, FPM and
console runtimes: a network call that never answers fails with an error
the application can log and report, instead of being stopped by Lambda.
@mnapoli mnapoli changed the title End network timeouts before the Lambda timeout Set reasonable default network timeouts instead of "infinite" Nov 24, 2026

This branch was successfully deployed

1 active deployment
preview — f34404ec Deployed Nov 24, 2026 by mnapoli via deploy #141
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.

1 participant