Issue 4814: ftplib does not honour "timeout" parameter for active data connections (original) (raw)

Created on 2009-01-03 00:52 by giampaolo.rodola, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
ftplib.patch giampaolo.rodola,2009-01-08 01:53 Modified patch which invokes settimeout() *before* accept()
Messages (6)
msg78912 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2009-01-03 00:52
When using the optional ftplib.FTP()'s timeout parameter which specifies a timeout in seconds for blocking operations like the connection attempt, it is applied on both FTP control and passive data channel (if any). It is not applied for active (PORT/EPRT) data connections. The patch in attachment modifies ftplib so that when ntransfer method is called in active mode, timeout is applied on the resulting data connection.
msg79390 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2009-01-08 01:10
Your patch looks correct.
msg79392 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2009-01-08 01:53
I'm sorry, I realized right now that settimeout() should be used also *before* invoking accept(), to avoid the client to stall in case the server does not establish any connection. The second patch in attachment does that by using settimeout() straight into FTP.makeport() method.
msg97061 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-12-30 21:33
This looks good, of course. Perhaps you want to add a test, if it isn't too difficult to do so.
msg97095 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2009-12-31 14:25
This time it's not easy as I see no way to distinguish whether the timeout exception gets raised by the command or the control socket, as makeport() method implementation deals with both: host = self.sock.getsockname()[0] if self.af == socket.AF_INET: resp = self.sendport(host, port) # socket.timeout can be raised here else: resp = self.sendeprt(host, port) # ...here if self.timeout is not _GLOBAL_DEFAULT_TIMEOUT: sock.settimeout(self.timeout) # or here I think the best we can do is add a test which checks the timeout applied to the data socket resulting from a PASV/PORT request. That doesn't cover this specific bug at all but it's something which is currently missing and that it would be nice to have.
msg103650 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2010-04-19 22:30
Fixed as r80226 (2.7) and r80228 (3.2).
History
Date User Action Args
2022-04-11 14:56:43 admin set github: 49064
2010-04-19 22:30:45 giampaolo.rodola set status: open -> closedpriority: normalcomponents: + Library (Lib)type: behaviornosy:pitrou, vstinner, giampaolo.rodola, r.david.murraymessages: + resolution: fixedstage: resolved
2010-04-17 19:11:47 giampaolo.rodola set assignee: giampaolo.rodolanosy: + r.david.murray
2009-12-31 14:25:39 giampaolo.rodola set messages: +
2009-12-30 21:33:48 pitrou set messages: + versions: + Python 3.2, - Python 3.0
2009-12-30 19:36:27 giampaolo.rodola set nosy: + pitrou
2009-01-08 08:33:54 vstinner set files: - ftplib.patch
2009-01-08 01:53:48 giampaolo.rodola set files: + ftplib.patchmessages: +
2009-01-08 01:10:26 vstinner set nosy: + vstinnermessages: +
2009-01-03 00:52:13 giampaolo.rodola create