tcp.startListening can throw socket.error for EADDRINUSE on linux
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 6k
- Forks
- 1.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 10
Description
| nickw reported | |
|---|---|
| Trac ID | trac#7688 |
| Type | defect |
| Created | 2014-10-17 03:30:02Z |
http://twistedmatrix.com/trac/browser/trunk/twisted/internet/tcp.py#L974
The code here expects that an exception for a re-used port will be thrown during the socket.bind; but on Linux one can bind the same port twice unless there is an active listening socket bound to the address.
The exception occurring only at the socket.listen when SO_REUSEADDR is set, which is basically always in Twisted.
The code here anticipates that an exception for a re-used port will be thrown during the socket.bind; but (on Linux) one can bind the same port twice unless there is an active listening socket bound to the address.
The exception occurring only at the socket.listen when SO_REUSEADDR is set, which is always in Twisted.
For example, with two interleaved processes:
- process A: bind (success)
- process B: bind (success)
- process A: listen (success)
- process B: listen (socket.error: [Errno 98] Address already in use)
The socket.listen should also be inside the exception handler; it's a bit strange to have a CannotListenError exception that's not thrown in some cases of being unable to listen.
Searchable metadata
trac-id__7688 7688
type__defect defect
reporter__nickw nickw
priority__normal normal
milestone__
branch__
branch_author__
status__new new
resolution__None None
component__core core
keywords__socket_listen socket listen
time__1413516602442761 1413516602442761
changetime__1413516602442761 1413516602442761
version__None None
owner__None None
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with twisted/internet/tcp.py around line 974 and inspect the exception handler around socket.bind and socket.listen. Reproduce the interleaved two-process sequence described in the issue, then verify that an address-in-use failure from listen is reported as CannotListenError rather than socket.error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- linux, python
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100