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
diff --git a/src/txpkgupload/twistedftp.py b/src/txpkgupload/twistedftp.py
index bfc195b..a652553 100644
--- a/src/txpkgupload/twistedftp.py
+++ b/src/txpkgupload/twistedftp.py
@@ -177,23 +177,38 @@ class FTPWithEPSV(ftp.FTP):
177177
178 epsvAll = False178 epsvAll = False
179 supportedNetworkProtocols = (_AFNUM_IP, _AFNUM_IP6)179 supportedNetworkProtocols = (_AFNUM_IP, _AFNUM_IP6)
180 portsInUse = set()
180181
181 def connectionLost(self, reason):182 def connectionLost(self, reason):
182 ftp.FTP.connectionLost(self, reason)183 ftp.FTP.connectionLost(self, reason)
183 self.epsvAll = False184 self.epsvAll = False
184185
186 def cleanupDTP(self):
187 """
188 Overrides `cleanupDTP` to update the list of ports in use once DTPport
189 is closed.
190 """
191 port = self.dtpPort.getHost().port if self.dtpPort else None
192 super().cleanupDTP()
193
194 if port and port in self.portsInUse:
195 self.portsInUse.remove(port)
196
185 def getDTPPort(self, factory, interface=''):197 def getDTPPort(self, factory, interface=''):
186 """198 """
187 Return a port for passive access, using C{self.passivePortRange}199 Return a port for passive access, using C{self.passivePortRange}
188 attribute.200 attribute.
189 """201 """
190 for portn in self.passivePortRange:202 for portn in self.passivePortRange:
203 if portn in self.portsInUse:
204 continue
191 try:205 try:
192 dtpPort = self.listenFactory(portn, factory,206 dtpPort = self.listenFactory(portn, factory,
193 interface=interface)207 interface=interface)
194 except error.CannotListenError:208 except error.CannotListenError:
195 continue209 continue
196 else:210 else:
211 self.portsInUse.add(dtpPort.getHost().port)
197 return dtpPort212 return dtpPort
198 raise error.CannotListenError('', portn,213 raise error.CannotListenError('', portn,
199 "No port available in range %s" %214 "No port available in range %s" %

Subscribers

People subscribed via source and target branches

to all changes: