Bug 45571 - The kernel disallows to reuse sockets which have TIME_WAIT pending connections
Summary: The kernel disallows to reuse sockets which have TIME_WAIT pending connections
Alias: None
Product: Networking
Classification: Unclassified
Component: IPV4 (show other bugs)
Hardware: All Linux
: P1 high
Assignee: Stephen Hemminger
URL: http://bugs.winehq.org/show_bug.cgi?i...
Depends on:
Reported: 2012-08-04 11:13 UTC by Artem S. Tashkinov
Modified: 2019-07-15 07:15 UTC (History)
3 users (show)

See Also:
Kernel Version: 3.10 (all versions)
Tree: Mainline
Regression: No


Description Artem S. Tashkinov 2012-08-04 11:13:10 UTC
This is a follow up of the following bug report: http://bugs.winehq.org/show_bug.cgi?id=26031

It's not Wine's problem, as it can be easily reproduced with native Linux applications.

Bruno Jesus 2011-11-10 21:35:54 CST wrote:

> Well, after reading a lot of internet pages and trying several different
> attempts I think it's possible to say that it's a kernel bug or a
> characteristic of the kernel tcp implementation.
> The attached patch forces SO_REUSEADDR in before every bind in an attempt to
> fix the problem but it only works if the program exits cleanly (so the kernel
> sets the socket to TIME_WAIT), if you do "wineserver -k" the socket will
> remain
> opened in an unknow broken state and no applications will be able to use it
> (wine or native linux apps).
> Output of strace:
> getsockopt(24, SOL_SOCKET, SO_REUSEADDR, [0], [4]) = 0
> setsockopt(24, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
> bind(24, {sa_family=AF_INET, sin_port=htons(43012), sin_addr=inet_addr("0.    
> 0.0.0")}, 16) = -1 EADDRINUSE (Address already in use)
> It's possible to see that I'm checking if SO_REUSEADDR is enabled and then
> enable it. But the bind fails anyway.
Comment 1 Alan 2012-08-08 09:07:57 UTC
I don't think this is a bug - the re-use rules for an existing connection mean you can't re-use the same connection addressing for a time period.

Should be discussed on netdev@vger.kernel.org if you think otherwise
Comment 2 Artem S. Tashkinov 2013-07-28 20:12:14 UTC
Linus, what do you think?

I'm thinking that this bug is more than valid, since it's bolstered up by common sense.

If nothing else is listening to incoming connections how can _old_ _stale_ connections prevent an application from listening on the port? Windows has no qualms about allowing that, why the Linux kernel works differently?

I'm trying to think of any security implications (like a daemon died and another application reused its port, but 1) it's a rare situation 2) ports under 1024 are available for the root user only) and nothing comes to my mind.

In short let me disagree.

I will raise this topic on LKML if Linus doesn't reply here.
Comment 3 Stephen Hemminger 2013-07-29 14:54:40 UTC
The proper place for discussing this is netdev mailing list <netdev@vger.kernel.org>. LKML or Linus isn't going to care, and no one
looks at bugzilla for discussion.

The current socket API behavior is unlikely to be changed because so many
applications expect it.
Comment 4 manoj2patil 2019-07-15 07:15:39 UTC
i am using lentos 7.6 and wine 4.0 i have same issue please give solution

Note You need to log in before you can comment on or make changes to this bug.