Opened 12 years ago

Closed 8 years ago

Last modified 6 years ago

#2122 closed bug (Fixed)

lt1.6: Now supports port re-use via two simple flags

Reported by: bmnot Owned by: Cas
Priority: minor Milestone: 2.0.0
Component: Core Version: other (please specify)
Keywords: single port bind socket reuse Cc:

Description

Currently, setting up Deluge to use a single port is very unreliable (that is, disabling random incoming port, and setting a port range of something like "52100 to 52100").

The issue is that re-starting the daemon will most often lead to the desired port being in use and a new random one chosen by the system.

The reason is that when a program frees up a port on Linux, it doesn't get immediately freed. It goes into a TIME_WAIT state, where it is available for fast re-binding in case an application changes its mind and wants it again. It's not fully killed off until a few seconds later.

To re-bind on the same port, Deluge will have to use libtorrent 1.6, which finally supports the TCP socket options to re-use the same port even if it's in the TIME_WAIT state, as well as a new option that refuses to bind if the desired port is in use (rather than choosing a random port).

It's described at http://code.google.com/p/libtorrent/issues/detail?id=305 but basically works as follows:

When migrated to lt 0.16, always use the session::listen_reuse_address flag to ensure it is allowed to re-use a TIME_WAIT port. if random_port == false && from_port == to_port, use the session::listen_no_system_port flag too to ensure that the system cannot change the desired port from what you wanted. If we could not bind the single port we wanted, kill the daemon and log a fatal error saying "port in use".

Change History (3)

comment:1 Changed 10 years ago by Cas

  • Milestone changed from 1.4.0 to 2.0.0
  • Owner set to Cas
  • Status changed from new to assigned

comment:2 Changed 8 years ago by Cas

  • Component changed from Unknown to Core
  • Resolution set to Fixed
  • Status changed from assigned to closed

Fixed in develop: [5978b433d3ab68]

comment:3 Changed 6 years ago by Cas

  • Milestone changed from 2.0 to 2.0.0

Milestone renamed

Note: See TracTickets for help on using tickets.