Merge ~ines-almeida/txpkgupload:update-txpkgupload-dtpport-selection into txpkgupload:master

Proposed by Ines Almeida
Status: Merged
Approved by: Ines Almeida
Approved revision: 69c165feb25cc5927ed45704828cd3f118e9dc77
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~ines-almeida/txpkgupload:update-txpkgupload-dtpport-selection
Merge into: txpkgupload:master
Diff against target: 43 lines (+15/-0)
1 file modified
src/txpkgupload/twistedftp.py (+15/-0)
Reviewer Review Type Date Requested Status
Colin Watson Approve
Review via email: mp+455573@code.launchpad.net

Commit message

Add portsInUse set in txpkgupload code so that passive FTP doesn't reuse connected ports

Description of the change

Currently some dput uploads are failing in production. We suspect that txpkgupload is not selecting the right ports for users to use.

Possible considerations:
 - Would it be possible for a port to not be cleaned up after closing, hence limiting the port space we currently have?

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

There's definitely a non-zero risk of something like that, but I don't know how to assess how likely it is, and this seems worth a try. I guess we can at least check logs occasionally to see whether the data ports we're issuing seem to be growing without bound?

review: Approve
Revision history for this message
Ines Almeida (ines-almeida) wrote :

Sounds like a plan, we'll have to monitor that... I'll do some more testing in qastaging before deploying to production

Revision history for this message
Otto Co-Pilot (otto-copilot) wrote :
Revision history for this message
Otto Co-Pilot (otto-copilot) wrote :
69c165f... by Ines Almeida

Use actual dtpPort instead of assumed `portn` when getting passive FTP port

The dtpPort port number should be created from `portn`, but this change removes the need for that assumption altogether.

Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/txpkgupload/twistedftp.py b/src/txpkgupload/twistedftp.py
2index bfc195b..a652553 100644
3--- a/src/txpkgupload/twistedftp.py
4+++ b/src/txpkgupload/twistedftp.py
5@@ -177,23 +177,38 @@ class FTPWithEPSV(ftp.FTP):
6
7 epsvAll = False
8 supportedNetworkProtocols = (_AFNUM_IP, _AFNUM_IP6)
9+ portsInUse = set()
10
11 def connectionLost(self, reason):
12 ftp.FTP.connectionLost(self, reason)
13 self.epsvAll = False
14
15+ def cleanupDTP(self):
16+ """
17+ Overrides `cleanupDTP` to update the list of ports in use once DTPport
18+ is closed.
19+ """
20+ port = self.dtpPort.getHost().port if self.dtpPort else None
21+ super().cleanupDTP()
22+
23+ if port and port in self.portsInUse:
24+ self.portsInUse.remove(port)
25+
26 def getDTPPort(self, factory, interface=''):
27 """
28 Return a port for passive access, using C{self.passivePortRange}
29 attribute.
30 """
31 for portn in self.passivePortRange:
32+ if portn in self.portsInUse:
33+ continue
34 try:
35 dtpPort = self.listenFactory(portn, factory,
36 interface=interface)
37 except error.CannotListenError:
38 continue
39 else:
40+ self.portsInUse.add(dtpPort.getHost().port)
41 return dtpPort
42 raise error.CannotListenError('', portn,
43 "No port available in range %s" %

Subscribers

People subscribed via source and target branches

to all changes: