Skip to content

ext/ftp: throw an Error when ftp_nb_fget()/ftp_nb_fput() hit a busy connection - #23540

Open
lacatoire wants to merge 2 commits into
php:masterfrom
lacatoire:fix/ftp-nb-return-types-upstream
Open

ext/ftp: throw an Error when ftp_nb_fget()/ftp_nb_fput() hit a busy connection#23540
lacatoire wants to merge 2 commits into
php:masterfrom
lacatoire:fix/ftp-nb-return-types-upstream

Conversation

@lacatoire

@lacatoire lacatoire commented Sep 2, 2026

Copy link
Copy Markdown
Member

Reworked as suggested: the guard now throws instead of returning false, so the stub change is gone. The UPGRADING note is kept, rewritten for the new behavior — the warning and false are still going away for callers. Drop it if you would rather not carry the entry.

ftp_nb_fget() and ftp_nb_fput() answered an already busy connection with a warning and false, against a declared int return type. Reaching that guard means a transfer was started from inside another transfer — a programming mistake — so it throws an Error, as ftp_close() already does on the same in_use flag. Both declarations stay int.

The check stays ahead of the direction and closestream writes, so the running transfer is left untouched. The test reaches the guard through a stream wrapper that calls back into the extension mid transfer, so it needs no FTP server beyond the one the ftp tests already start.

ftp_nb_get() and ftp_nb_put() keep their warning and false for now: their int|false is also returned when the local file cannot be opened, so the declaration would not change. Happy to convert their in_use guard too if you want the four consistent.

@ndossche

ndossche commented Sep 2, 2026

Copy link
Copy Markdown
Member

Perhaps the code should be revised to throw an Error rather than returning false. Generally, Error is used to indicate a programming mistake, and this is the case here. I believe that's more appropriate than widening the return type

@ndossche

ndossche commented Sep 2, 2026

Copy link
Copy Markdown
Member

cc @iliaal

@iliaal

iliaal commented Sep 3, 2026

Copy link
Copy Markdown
Member

Agreed, ftp_close() already throws an Error on the same in_use flag. That guard is the only false in ftp_nb_fget() and ftp_nb_fput(), so throwing drops the stub and UPGRADING changes entirely. Keep the check ahead of the direction/closestream writes, and master only.

ftp_nb_fget() and ftp_nb_fput() answered an already busy connection with a
warning and false, against a declared int return type. Reaching that guard
means a transfer was started from inside another transfer, which is a
programming mistake, so throw an Error instead, as ftp_close() already does
on the same in_use flag. The declarations stay int.

The check stays ahead of the direction and closestream writes, so the
running transfer is left untouched. The test reaches the guard through a
stream wrapper that calls back into the extension mid transfer.
@lacatoire
lacatoire force-pushed the fix/ftp-nb-return-types-upstream branch from 6a0827e to fa921f8 Compare September 3, 2026 12:59
@lacatoire lacatoire changed the title ext/ftp: declare the false returned by ftp_nb_fget() and ftp_nb_fput() ext/ftp: throw an Error when ftp_nb_fget()/ftp_nb_fput() hit a busy connection Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants