ext/ftp: throw an Error when ftp_nb_fget()/ftp_nb_fput() hit a busy connection - #23540
ext/ftp: throw an Error when ftp_nb_fget()/ftp_nb_fput() hit a busy connection#23540lacatoire wants to merge 2 commits into
Conversation
|
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 |
|
cc @iliaal |
|
Agreed, |
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.
6a0827e to
fa921f8
Compare
ndossche
left a comment
There was a problem hiding this comment.
This is the right direction, but incomplete.
You should consistently do the same for ftp_nb_get & ftp_nb_put, such that this entire error class (which is rlly a programming error), can be handled in a consistent way.
| the integer index is greater than INT_MAX instead of overflowing to a | ||
| smaller index. | ||
|
|
||
| - FTP: |
There was a problem hiding this comment.
Correct me if I'm wrong, but the original fix (that caused this return-type-mismatch issue) went into master-only right? If so, then instead of emitting a warning and returning false against their declared int return type. is confusing and can go away.
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()andftp_nb_fput()answered an already busy connection with a warning andfalse, against a declaredintreturn type. Reaching that guard means a transfer was started from inside another transfer — a programming mistake — so it throws anError, asftp_close()already does on the samein_useflag. Both declarations stayint.The check stays ahead of the
directionandclosestreamwrites, 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()andftp_nb_put()keep their warning andfalsefor now: theirint|falseis also returned when the local file cannot be opened, so the declaration would not change. Happy to convert theirin_useguard too if you want the four consistent.